HTML/CSS popstate 事件

aini · June 22, 2018 · Last by aini replied at June 28, 2018 · 6261 hits

HTML 中即便进入了那些非 pushState 和 replaceState 方法作用过的没有 state 对象关联的那些网页,popstate 事件也仍然会被触发。
求教!现在我不想让其他页面触发 popstate 事件,应该怎么做?
补充:在我用了 popstate 之后点击回退,有些时候会一直弹出提示框(我这里的逻辑是,点击回退弹出提示框)。

先解绑 popstate 事件,进入其他页面,再重新绑定 popstate 事件

Reply to luikore

我用的

window.onpopstate = function(){}

这个需要解绑吗?

Reply to aini
window.onpopstate = undefined // 解绑
// 搞事情
window.onpopstate = funcion() {} // 重新绑
Reply to luikore

非常感谢!

You need to Sign in before reply, if you don't have an account, please Sign up first.