也許這會適合你。
<html>
<body onunload="disableBackButton()">
<h1>You should not come back to this page</h1>
</body>
<script>
function disableBackButton()
{
window.history.forward();
}
setTimeout("disableBackButton()", 0);
</script>
</html>
上面的代碼會使後面的按鈕很難加載這個頁面。
第二次嘗試
下面的代碼取自另一個堆棧溢出。
detect back button click in browser
window.onload = function() {
if (typeof history.pushState === "function") {
history.pushState("jibberish", null, null);
window.onpopstate = function() {
history.pushState('newjibberish', null, null);
// Handle the back (or forward) buttons here
// Will NOT handle refresh, use onbeforeunload for this.
};
}
else {
var ignoreHashChange = true;
window.onhashchange = function() {
if (!ignoreHashChange) {
ignoreHashChange = true;
window.location.hash = Math.random();
// Detect and redirect change here
// Works in older FF and IE9
// * it does mess with your hash symbol (anchor?) pound sign
// delimiter on the end of the URL
}
else {
ignoreHashChange = false;
}
};
}
}
保持上次訪問的頁面的跟蹤,如果當前頁面重定向到最近訪問過的頁面,沒準方向是向下。 – adeneo 2013-05-14 16:21:16
如果你通過一個例子來說明會更好。問候 – 2013-05-15 00:25:59
PushState在堆棧中推送新狀態(狀態是在新操作之後存儲的一些數據)。它與後退沒有關係。返回並去是用於在堆棧中的推送狀態上導航的功能。我這樣說是因爲在你的編輯中,你認爲pushState和go(1)是等價的。 – 2013-05-18 23:22:29