popstate

今天测试一个h5中的popstate事件,虽然我很久之前就对这个新属性有所学习,
https://blog.csdn.net/zgrbsbf/article/details/25297359
无奈今天还是犯了几个小错误,记录如下:

错误:

https://developer.mozilla.org/en-US/docs/Web/Events/popstate
这篇文章中说,

The popstate event is fired when the active history entry changes.

然后我写了个例子测试,2个页面,每个中都有a链接,两个页面互相跳转,两个页面都对window添加了popstate事件,无奈就是不触发。难道是我写的有什么问题吗,我感觉没有啊。

正确:

后来我又写了个页面,新页面中pushState了一下,也添加了popstate事件,搞了个定时器history.back之后,pop触发了!
https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate

A popstate event is dispatched to the window each time the active history entry changes between two history entries for the same document.

同一个文档中的两个历史记录,这是重点。但是第一个文献中就没讲清楚,害得我误解。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值