禁止页面后退,如火狐或者谷歌左上角的左箭头
1 JS
//防止页面后退
            history.pushState(null, null, document.URL);
            window.addEventListener('popstate', function () {
                history.pushState(null, null, document.URL);
            });
2 用jQuery
$(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);
                $("#label").html("第" + (++counter) + "次单击后退按钮。");
            });
        }
//PS:
        window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
        window.history.forward(1);
        });

标签: none

添加新评论