使用用js代码禁用浏览器的后退按钮

这里使用了jquery,先引入jquery

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
function disableBack() {
    if (window.history && window.history.pushState) {
        $(window).on('popstate', function () {
            window.history.pushState('forward', null, '');
            window.history.forward(1);
        });
    }
    window.history.pushState('forward', null, '');
    window.history.forward(1);
}

在页面初始化时调用上面的函数即可。

猜你喜欢

转载自www.cnblogs.com/xl5230/p/11572344.html