今天在做web项目时,对浏览器自带的前进后退按钮进行静止,防止登录后,后退回登录没有清session问题
//这种方式,可以消除 后退的所有动作。包括 键盘、鼠标手势等产生的后退动作。
<script language="javascript">
//防止页面后退
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});
</script>
//现在,我们项目中就使用了第三种方式。在常用浏览器中,都可以禁用了后退。
//禁用浏览器返回
function fobidden_back() {
//防止页面后退
history.pushState(null, null, document.URL);
window.addEventListener('popstate',back_common)
}
//启用浏览器返回
function enable_back() {
history.go(-1);
window.removeEventListener('popstate',back_common)
}
function back_common() {
history.pushState(null, null, document.URL);
}
转载 : https://www.cnblogs.com/sunshq/p/7976827.html