js禁止浏览器页面后退功能的实例(推荐)

实例如下所示:

<script>
 $(function(){
   if(window.location.href.indexOf("/login") > -1) {
    //防止页面后退
     history.pushState(null, null, document.URL);
     window.addEventListener('popstate', function () {
      history.pushState(null, null, document.URL);
     });
   }
 });
</script>

以上这篇js禁止浏览器页面后退功能的实例(推荐)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持来客网。