Cod*_*iak 23 javascript php ajax .htaccess jquery
我使用.htaccess将我的所有流量路由到单个index.php文件.下面的代码用于指示流量,但由于某种原因,它不能与后退按钮一起使用.我不知道如何让后退按钮工作.我已经尝试了各种各样的东西,谷歌搜索了一点,没有一个有效,所以我希望有人在这里可以提供帮助!
<?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';
?>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已尝试过但未能使用: window.onbeforeunload
body onunload=""
必须有办法onunload=location.reload()或某事!不知何故必须知道语法!!
Gop*_*pal 43
试试这个...未经测试.我希望它对你有用.
制作一个新的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>
Run Code Online (Sandbox Code Playgroud)
要么
找到另一个解决方
当用户点击后退按钮时,应该触发onload事件.不是通过JavaScript创建的元素将保留其值.我建议在INPUT TYPE ="hidden"设置中保留动态创建元素中使用的数据的备份,以显示: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();}
}
Run Code Online (Sandbox Code Playgroud)
sfs*_*scs 32
最新的解决方案是使用PerformanceNavigation接口:
if(!!window.performance && window.performance.navigation.type === 2)
{
console.log('Reloading');
window.location.reload();
}
Run Code Online (Sandbox Code Playgroud)
值2表示"通过导航到历史记录访问页面".
在此处查看浏览器支持:http: //caniuse.com/#search=Navigation%20Timing%20API
t0v*_*ana 13
隐藏的输入解决方案在Safari中不适用于我.下面的解决方案有效,来自这里.
window.onpageshow = function(event) {
if (event.persisted) {
window.location.reload()
}
};
Run Code Online (Sandbox Code Playgroud)
我找到了两种方法来处理这个问题.选择最适合您的情况.在Firefox 53和Safari 10.1上测试的解决方案
1.检测用户是否正在使用后退/前进按钮,然后重新加载整页
if (!!window.performance && window.performance.navigation.type === 2) {
// value 2 means "The page was accessed by navigating into the history"
console.log('Reloading');
window.location.reload(); // reload whole page
}
Run Code Online (Sandbox Code Playgroud)
2.如果页面被缓存,则重新加载整个页面
window.onpageshow = function (event) {
if (event.persisted) {
window.location.reload();
}
};
Run Code Online (Sandbox Code Playgroud)
这个简单的解决方案贴在这里强制页面刷新后退按钮工作...
当用户点击后退按钮时,我试图通过浏览器强制再次下载页面,但没有任何效果.我看来,现代浏览器具有单独的页面缓存,它存储页面的完整状态(包括JavaScript生成的DOM元素),因此当用户按下后退按钮时,前一页面立即显示在用户离开的状态.如果要强制浏览器重新加载后退按钮上的页面,请将onunload =""添加到(X)HTML body元素:
<body onunload="">
这会禁用特殊缓存并在用户按下按钮时强制页面重新加载.使用前请三思而后行.需要这种解决方案的事实是暗示您的网站导航概念存在缺陷.