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

2024-03-17

是否可以在 JavaScript 中捕获“History.Back”事件? 我想抓住history.back()事件和注销用户。

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

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

然后设置onunload event

<body onunload="disableBackButton()">

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 JavaScript 中捕获“History.Back”事件? 的相关文章

随机推荐