How to catch “History.Back” event in javascript?

自闭症网瘾萝莉.ら 提交于 2019-12-21 09:16:06

问题


is it posible to catch "History.Back" event in javascript? İ want to catch history.back() event and logout user.

P.s : There is some code about disabling history.back(). But is not useful for me.

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

then set onunload event

<body onunload="disableBackButton()">

回答1:


You can catch history back using "window.onpopstate" event. But AFAIK it is only available in HTML5.

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



来源:https://stackoverflow.com/questions/4967414/how-to-catch-history-back-event-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!