且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在点击后退按钮时刷新页面?

更新时间:2023-12-02 22:56:46

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

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