gpt4 book ai didi

javascript - 如何在单击后退按钮时刷新页面?

转载 作者:IT王子 更新时间:2023-10-28 23:50:27 25 4
gpt4 key购买 nike

我使用 .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.onbeforeunloadbody onunload=""

必须有一种方法来 onunload=location.reload() 什么的!不知何故必须知道语法!

最佳答案

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

创建一个新的 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 中保留动态创建元素中使用的数据的备份,然后使用输入的值加载以将动态元素重建为它们原来的样子。

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

关于javascript - 如何在单击后退按钮时刷新页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20899274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com