如何在javascript中捕获“History.Back”事件?

时间:2011-02-11 09:28:57

标签: javascript javascript-events

可以在javascript中捕获“History.Back”事件吗? 我想要捕获history.back()事件和注销用户。

P.s:有一些关于禁用history.back()的代码。但对我没用。

<script type = "text/javascript" >
 function disableBackButton()
 {
   window.history.forward();
 }
 setTimeout("disableBackButton()", 0);
</script>

然后设置onunload事件

<body onunload="disableBackButton()">

1 个答案:

答案 0 :(得分:2)

您可以使用“window.onpopstate”事件捕获历史记录。但是AFAIK只能在HTML5中使用。

http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#event-definitions-0