如何在点击后退按钮时刷新页面? [英] How to refresh page on back button click?

查看:26
本文介绍了如何在点击后退按钮时刷新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 .htaccess 将所有流量路由到单个 index.php 文件.下面的代码用于引导流量,但由于某种原因它不适用于后退按钮.我不知道该怎么做才能让后退按钮工作.我尝试了各种各样的东西,并在谷歌上搜索了很多,但都没有奏效,所以我希望这里有人可以提供帮助!

I use .htaccess to route all of my traffic to a single index.php file. The code below to directs traffic, but for some reason it doesn't work with the back button. I don't know what to do to get the back button working. I've tried a variety of things and googled quite a bit and none of it has worked so I'm hoping someone here can help!

<?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.onbeforeunloadbody onunload=""

So far I've tried and failed to use: window.onbeforeunload body onunload=""

必须有一种方法可以onunload=location.reload() 或其他什么!不知何故必须知道语法!!

There has got to be a way to onunload=location.reload() or something! Somehow has to know the syntax!!

推荐答案

试试这个……未测试.我希望它对你有用.

Try this... not tested. I hope it will work for you.

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

Make a new php file. You can use the back and forward buttons and the number/timestamp on the page always updates.

<?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 创建的元素将保留它们的值.我建议在设置为 display:none 的 INPUT TYPE="hidden" 中保留动态创建元素中使用的数据的备份,然后使用输入的值将动态元素重建为它们原来的样子.

The onload event should be fired when the user hits the back button. Elements not created via JavaScript will retain their values. I suggest keeping a backup of the data used in dynamically created element within an INPUT TYPE="hidden" set to display:none then onload using the value of the input to rebuild the dynamic elements to the way they were.

<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();}
}

这篇关于如何在点击后退按钮时刷新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆