也许这会适合你。
<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