小编典典

如何刷新后退按钮上的页面?

javascript

我使用.htaccess将所有流量路由到单个index.php文件。以下代码用于引导流量,但由于某些原因,它无法与“后退”按钮一起使用。我不知道该怎么做才能使后退按钮正常工作。我已经尝试过各种方法,并且在Google上搜索了很多,但都没有起作用,所以我希望这里的人能为您提供帮助!

<?php
   if(isset($_GET['parameters'])) {
      if($_GET['parameters'] == "repair")
         include 'repair.html';
      else if($_GET['parameters'] == "training")
         include 'training.html';
      else if($_GET['parameters'] == "products")
         include 'products.html';
      else if($_GET['parameters'] == "about")
         include 'about.html';
      else if($_GET['parameters'] == "employees")
         include 'employees.html';
      else if($_GET['parameters'] == "training")
         include 'training.html';
      else if($_GET['parameters'] == "newaccount")
         include 'newaccount.html';
      else if($_GET['parameters'] == "contact")
         include 'contact.html';
      else if($_GET['parameters'] == "recommended")
         include 'recommended.html';
      else if($_GET['parameters'] == "careers")
         include 'careers.html';
      else
         include 'home.html';
   }
   else
      include 'home.html';
?>

到目前为止,我已经尝试并未能使用: window.onbeforeunload body onunload=""

必须有一条通往之路onunload=location.reload()!不知何故必须知道语法!!


阅读 334

收藏
2020-05-01

共1个答案

小编典典

试试这个…未经测试。希望它对您有用。

制作一个新的php文件。您可以使用后退和前进按钮,页面上的数字/时间戳将始终更新。

<?php
header("Cache-Control: no-store, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
echo time();
?>
<a href="http://google.com">aaaaaaaaaaaaa</a>

要么

找到了另一个解决方案

用户单击“后退”按钮时应触发onload事件。不是通过JavaScript创建的元素将保留其值。我建议将INPUT TYPE =“
hidden”中设置为动态创建的元素中使用的数据备份,设置为display:none,然后使用输入的值进行onload来按原样重建动态元素。

<input type="hidden" id="refreshed" value="no">
<script type="text/javascript">
onload=function(){
var e=document.getElementById("refreshed");
if(e.value=="no")e.value="yes";
else{e.value="no";location.reload();}
}
2020-05-01