js监听浏览器后退事件

Posted 思考的大腿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js监听浏览器后退事件相关的知识,希望对你有一定的参考价值。

$(document).ready(function(e) { 
            var counter = 0;
            if (window.history && window.history.pushState) {
                             $(window).on(‘popstate‘, function () {
                                            window.history.pushState(‘forward‘, null, ‘#‘);
                                            window.history.forward(1);
                                          alert("不可回退");
                                });
              }

              window.history.pushState(‘forward‘, null, ‘#‘); //在IE中必须得有这两行
              window.history.forward(1);
});

以上是关于js监听浏览器后退事件的主要内容,如果未能解决你的问题,请参考以下文章