禁用浏览器的返回按钮

1. 方法一: 超好用, 收藏

<script language="javascript">
  //防止页面后退, 目前仅适用于chrome,Firefox,360极速模式
  history.pushState(null, null, document.URL);
  if (window.addEventListener) {
    history.pushState(null, null, document.URL);
    window.addEventListener('popstate', function () {
      history.pushState(null, null, document.URL);
      scrollTo(0,0);
    });
  } else if (window.attachEvent) {
    window.attachEvent('onpopstate', function () {
      history.pushState(null, null, document.URL);
      scrollTo(0,0);
    });
  }
</script>

2. 方法二: url没有变但是页面还会刷新

<script language="JavaScript"> 
    javascript:window.history.forward(1); 
</script>

 

posted @ 2017-08-24 19:43  李晓菲  阅读(459)  评论(0编辑  收藏  举报