使浏览器不可后退 的代码(兼容性特别高),监听用户是否在此页面浏览

 1  <script type="text/javascript">
 2      window.onbeforeunload = function () { 
 3     alert("离开此页面");
 4      }    
 5      // window 每次获得焦点
 6      window.onfocus = function () {
 7     alert("返回此页面");
 8         
 9      }
10 </script>
浏览器不可返回代码

<script>
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});


</script>
原文地址:https://www.cnblogs.com/whatarey/p/8960909.html