如何防止页面加载时的popstate事件(android浏览器)

时间:2016-07-13 09:18:00

标签: javascript events android-browser popstate

如何阻止在页面加载时触发popstate事件? (这在Android浏览器上发生)

在Android浏览器上运行以下代码段并查看结果。 (替代链接ro运行代码段:https://jsfiddle.net/heoceze0/1



window.onpopstate = function (e) {
  alert('popstate is called!!!');
};

If you got no alert, that's ok...




1 个答案:

答案 0 :(得分:-2)

每当活动历史记录条目在同一文档的两个历史记录条目之间发生更改时,就会将popstate事件分派到窗口。

为了防止它被触发,只需使用event.preventDefault()

window.onpopstate = function (event) {
  event.preventDefault();
  alert('popstate is called!!!');
};
相关问题