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

may*_*cil 9 javascript javascript-events

在javascript中捕获"History.Back"事件是否可行?©想要捕获history.back()事件和注销用户.

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

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

然后设置onunload事件

<body onunload="disableBackButton()">
Run Code Online (Sandbox Code Playgroud)

小智 3

您可以使用“window.onpopstate”事件捕获历史记录。但据我所知,它仅适用于 HTML5。

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