js禁止浏览器页面后退功能

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>

 

posted @ 2017-08-31 20:04  前端站  阅读(5218)  评论(0编辑  收藏  举报