可以在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()">
答案 0 :(得分:2)
您可以使用“window.onpopstate”事件捕获历史记录。但是AFAIK只能在HTML5中使用。
http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#event-definitions-0