监听同一文档的浏览历史变动
window.onpopstate = function(res) {
console.log(res)
}
注意:
pushState()或replaceState()不能触发该事件;- 用户点击前进、后退,或
History.back()、History.forward()、History.go()可以触发,前提是 HTML 文档得是同一个。 - 页面第一次加载的时候,浏览器不会触发
popstate事件;
window.onpopstate = function(res) {
console.log(res)
}
注意:
pushState()或replaceState()不能触发该事件;History.back()、History.forward()、History.go()可以触发,前提是 HTML 文档得是同一个。popstate事件;