这篇文章主要为大家详细介绍了js禁止浏览器的回退事件,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
直接来个终极方案:
查找了好多资料才找到的,这种方式,可以消除 后退的所有动作。包括 键盘、鼠标手势等产生的后退动作。
现在,我们项目中就使用了这种方式。在常用浏览器中,都可以禁用了后退。
具体实例:
$(function(){
if (window.history && window.history.pushState) {
history.pushState(null, null, document.URL);
window.addEventListener('popstate', forbidBack);
}
})
/**
* 禁止回退按钮
*/
function forbidBack(){
appUtils.mobileConfirm("确定放弃重置密码?",function(){//yes
window.removeEventListener('popstate',forbidBack);
muiwindow.muiwebview({"url":"login.html"});
},function(){//no
//防止页面后退
history.pushState(null, null, document.URL);
});
}需要学习js的同学请关注php中文网js视频教程,众多js在线视频教程可以免费观看!










