
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
1.4.2 hashchange事件
hashchange事件用于监听浏览器hash值的变化,其监听方式为

hashchange事件可以通过设置location.hash、在地址栏中手动修改hash、调用window.history.go、在浏览器中单击“前进”或“后退”按钮等方式触发。
在hashchange事件的事件响应函数中,可获取事件对象HashChangeEvent,其除了继承事件对象Event,拥有Event的属性,如target、type,还提供oldURL、newURL,分别表示hash跳转前的URL及hash跳转后的URL。


注意,window.history.pushState不会触发hashchange事件,即使前后导航的URL仅hash部分不同,也是如此,如:
