点击回退按钮刷新页面

浏览器用户返回上一步,自动刷新
window.onunload=function(){} 这个最简单粗暴

方式一、
<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();}
}

//ios 由于其回退的机制问题导致js不会去执行,得添加如下写法
var browserRule = /^.*((iPhone)|(iPad)|(Safari))+.*$/;
if (browserRule.test(navigator.userAgent)) {
    window.onpageshow = function(event) {
        if (event.persisted) {
            window.location.reload()
        }
    };
}
ps:在ios可能出现未知错误,在使用微信支付时页面偶现卡死现象

方式二、
 header("Cache-Control: no-store, must-revalidate, max-age=0");
 header("Pragma: no-cache");
 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
方式三、
 window.onpageshow = function(event) {if (event.0) {    window.location.reload() }};
方式四、直接在进行页面跳转的时候使用window.location.replace()跳转,直接就没有了回退问题了


拿来试了下,第一个方法较好,第二个会有一些兼容性问题,效果不是很好

猜你喜欢

转载自blog.csdn.net/q15642/article/details/78037705
今日推荐