加载中...
加载中...
在有验证码的登陆页面,浏览器按返回上一个,验证码不刷新

在有验证码的登陆页面,浏览器按返回上一个,验证码不刷新 转载

场景描述:

在有验证码的登陆页面,跳转到别的页面后,在浏览器按返回上一个页面,验证码不刷新,这可不行,太不安全了。


解决可参考:

如下代码可解决

效果:

Chrome 时间很短几秒钟之内返回不刷新,反之刷新。

2345加速浏览器也是。

复制收展JavaScript<!-- 浏览器后退事件   ---  监听浏览器左上角的后退按钮 -->
$(document).ready(function(e) {
var counter = 0;
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
window.history.pushState('forward', null, '#');
window.history.forward(1);

<!-- 此处为监听到浏览器后退按钮的后续事件 例:刷新前一个页面;或者刷新当前页面等-->
//window.location.href = window.location.reload();
changeCode();
});
}
window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
window.history.forward(1);
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16


原文:

https://blog.csdn.net/qq_37121548/article/details/80903021?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-8  

可参考:

https://stackoverflow.com/questions/17432899/javascript-bfcache-pageshow-event-event-persisted-always-set-to-false    


没有更多推荐了 [去首页]
image
文章
376
原创
293
转载
83
翻译
0
访问量
183398
喜欢
73
粉丝
5
码龄
7年
资源
3

文章目录

加载中...
0
0