1.可以消除 后退的所有动作。包括 键盘、鼠标手势等产生的后退动作。
<script language="javascript"> //防止页面后退 history.pushState(null, null, document.URL); window.addEventListener('popstate', function () { history.pushState(null, null, document.URL); }); </script>
2.系统登录退出后,跳转到登录页面,登录页面点击浏览器后退按钮,页面后退到之前登录的页面。在退出登录后,禁止浏览器点击后退按钮,进行页面回退;
window.location.hash="no-back"; window.location.hash="Again-No-back-button"; window.onhashchange=function(){window.location.hash="no-back";}
3.系统中嵌入iframe,映入其他页面。当session失效时,点击导航后,由于后台做了登录拦截,此时iframe中就会嵌入登录页面;当session失效时,希望系统可以跳转到登录页面中;
/** * [loadTopWindow 判断是否有顶层窗口,登录超时跳转] * @return {[type]} [description] */ function loadTopWindow() { if (window.top != null && window.top.document.URL != document.URL){ window.top.location = document.URL; } } <body onload="loadTopWindow()"></body>
本文转载自:https://segmentfault.com/a/1190000017130201
更多web前端开发知识,请查阅 HTML中文网 !!
以上就是JavaScript如何禁止页面回退?(方法介绍)的详细内容,更多请关注0133技术站其它相关文章!