【问题标题】:How to catch "History.Back" event in javascript?如何在javascript中捕捉“History.Back”事件?
【发布时间】:2011-02-11 09:28:56
【问题描述】:

是否可以在 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()">

【问题讨论】:

  • 不要这样做 - 重新考虑你的设计。

标签: javascript javascript-events


【解决方案1】:

您可以使用“window.onpopstate”事件来获取历史记录。但 AFAIK 它仅在 HTML5 中可用。

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

【讨论】:

    猜你喜欢
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 2019-03-01
    • 1970-01-01
    相关资源
    最近更新 更多