Disable browser's back button

2018-12-31 06:38发布

How to disable browser's BACK Button (across browsers)?

20条回答
弹指情弦暗扣
2楼-- · 2018-12-31 07:21
<body onLoad="if(history.length>0)history.go(+1)">
查看更多
旧人旧事旧时光
3楼-- · 2018-12-31 07:21

The problem with Yossi Shasho's Code is that the page is scrolling to the top every 50 ms. So I have modified that code. Now its working fine on all modern browsers, IE8 and above

var storedHash = window.location.hash;
function changeHashOnLoad() {
    window.location.href += "#";
    setTimeout("changeHashAgain()", "50");
}

function changeHashAgain() {
    window.location.href += "1";
}

function restoreHash() {
    if (window.location.hash != storedHash) {
        window.location.hash = storedHash;
    }
}

if (window.addEventListener) {
    window.addEventListener("hashchange", function () {
        restoreHash();
    }, false);
}
else if (window.attachEvent) {
    window.attachEvent("onhashchange", function () {
        restoreHash();
    });
}
$(window).load(function () { changeHashOnLoad(); });
查看更多
登录 后发表回答