简体   繁体   English

批准的在同一网站上的页面之间导航的方法

[英]Approved method to navigate between pages on same website

I have researched many places to find an answer to this question, but they never quite answer my real question: What is the best/approved way to move to a new page within the same website? 我已经研究了许多地方来找到该问题的答案,但是他们从来没有完全回答我的真实问题:在同一网站内转到新页面的最佳/批准方式是什么? I have read that it is bad to use window.location because search engines will think you are hiding something. 我已经读到使用window.location是不好的,因为搜索引擎会认为您隐藏了某些东西。 But, when I don't want to open a new window (window.open), then I don't know how else to do it. 但是,当我不想打开新窗口(window.open)时,我不知道该怎么做。 I use href anchors in links and form actions, where appropriate. 在适当的地方,我在链接和表单操作中使用了href锚。 But when I have menus or buttons with onclick, then I need something else. 但是,当我具有带有onclick的菜单或按钮时,则需要其他功能。

Here's an snippet of my code: 这是我的代码片段:

my javascript: (with one option commented) 我的javascript :(带有一个选项的注释)

function gotoCat() {
   var catcdF = document.catSelect.catcd.value; 
   <?php 
   echo "window.location.href='http://www.mysite.org".$pgmdir."services/busMenu.php?catF='+catcdF; ";
   /*
   echo "window.open('http://www.mysite.org".$pgmdir."services/busMenu.php?catF='+catcdF,'','resizable=1,scrollbars=1,toolbar=1,top=50,left=300,width=950,height=800,location=0'); ";
   */
   ?>
} 

My dynamic SELECT list in a form (within PHP): 我的动态SELECT列表的格式(在PHP中):

   echo " <select name='catcd' id='catcd' size='8' onclick=gotoCat() > \n"; 
             // display list of categories   
     if ($numcats == 0) { // print message text only
        echo "<option value='0' >".$catMsg."</option> \n";
     }
     else {
        for ($i=1; $i<=$numcats; $i++) {
         $catcd_db = $catAry[$i][1];
         $catName_db = $catAry[$i][2];
         echo "<option value='".$catcd_db."'> ".$catName_db." </option> \n";   
        }
     }
  echo "</select>";

So, as you can see, I just want a method to allow the user a choice and then automatically go to the correct web page once selected. 因此,正如您所看到的,我只希望有一种方法允许用户选择,然后一旦选择就自动进入正确的网页。 This is not always in a select list. 这并不总是在选择列表中。 Often it's when they want to exit or get an error: 通常是他们想退出或出现错误的时候:

     if (mysqli_connect_errno()) { 
       echo "<br/> <p style='text-align:center;'> <button type='button' 
           class='buttonStyle' style='padding: 4px 20px;' value='Exit' ";
       echo "onClick=\"window.location.href='http://www.mysite.org/services/catSelbus.php?rc=1&func=Rev'\" > ";  
       echo "Exit </button></p> ";
    }

I cannot use "go back" because they need to go to a prior page, not the form they came from. 我不能使用“返回”,因为它们需要转到上一页,而不是它们来自的表单。

So, unless my navigation methods are really off-the-mark, I guess I need to know the acceptable method for using javascript onClick to move to the next page in the same website. 因此,除非我的导航方法确实不可行,否则我想我需要知道使用javascript onClick移至同一网站的下一页的可接受方法。 Is window.location okay, or should I use something else? window.location可以,还是应该使用其他东西?

Any opinions or suggestions are welcome! 欢迎任何意见或建议!

To navigate to another page using Javascript, use: 要使用Javascript导航到另一个页面,请使用:

window.location.href = "url";

That's how it's done and there's nothing wrong about it. 这就是完成的方式,没有错。


For the sake of argument, you could create a hidden link and simulate a click on it, but as I said, there's really no need. 为了争辩,您可以创建一个隐藏的链接并模拟对其的单击,但是正如我所说,确实没有必要。

You can use php header('location') instead: 您可以使用php header('location')代替:

<form action="submit.php">

<input type="hidden" value="test" name="hidden1" />
<input type="submit" Value="Exit" ... />

submit.php Submit.php

<?php
  if (isset($_POST['hidden1'])
  {
    header('Location: http://www.mysite.org/services/catSelbus.php?rc=1&func=Rev');
    exit;
  }
?>

More info about header('Location ...'); 有关header('Location ...');更多信息 : http://php.net/manual/en/function.header.php http//php.net/manual/en/function.header.php

Instead of a hidden, you use your select 's value and get it via the $_POST variable. 您可以使用select的值而不是隐藏的值,并通过$_POST变量获取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM