这种方式,可以消除 后退的所有动作。包括 键盘、鼠标手势等产生的后退动作。
<script language="javascript">
//防止页面后退
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});
</script>
实例:
复制代码
$(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);
});
}