【发布时间】:2015-04-11 00:53:55
【问题描述】:
我正在使用 pushState 并根据当前页面的 history.state 生成关于 popstate 事件的页面视图。
如果没有history.state我(希望)重新加载文档。
window.onpopstate = function(event) {
if( window.history.state !== null ){
// page was ajax created and history created by pushState
// recreate with ajax
}
else{
// page was loaded from server normally
document.location.reload()
}
}
问题在于 Safari 在初始页面加载时会触发 popstate 事件。 Chrome 和 Firefox 在后退/前进浏览器按钮上触发 popstate。
我想忽略 Safari 上的初始加载 popstate 事件(最好没有 setTimeout 并且没有浏览器检测)。
此外,该网站是混合的链接 - 一些会触发 pushState 和一些会从服务器正常加载 - 所以如果用户进入导航历史的十页并点击后退按钮,历史将有一个混合pushState 页面和非 pushState 页面。
【问题讨论】:
-
Question about the same bug in Chrome, which was also webkit-based, has lots of answers。顺便说一句,我在最近的 Safari 11.1.2 中没有看到这种行为。
标签: javascript jquery safari