【问题标题】:History.js vs. window.history for HTML5-only mode仅 HTML5 模式的 History.js 与 window.history
【发布时间】:2013-04-26 11:49:02
【问题描述】:
History.js 现在与 HTML5 的 window.history 相比有什么实质性的优势吗?我们对支持/退回到 HTML4 hashbang URL 不感兴趣。
History.js doesn't support anchors in pushState(),而 window.history 可以。我们需要这个功能,所以如果没有很大的理由在 HTML5 模式下使用 History.js 而不是原生 window.history,我们宁愿选择后者。
【问题讨论】:
标签:
html
browser-history
pushstate
history.js
html5-history
【解决方案1】:
是的 - 他们在他们的网站上说:
为所有 HTML5 浏览器提供交叉兼容的体验(它们都实现 HTML5 >History API 略有不同,导致不同的行为,有时会出现错误 - >History.js 修复了这个问题,确保体验符合预期/相同/很棒贯穿 >HTML5 浏览器)
这些差异很小,谷歌搜索不足以找到它们——我不得不查看源代码——似乎主要是修复了 safari 中的 HTML5 功能。
Safari 实现存在两个问题 - 一个是 history.back 无法返回由 location.hash 设置的哈希状态,该状态随后被 history.replaceState 替换。
第二个是safari在忙碌的时候将无法应用状态改变。
相关History.js源码:
History.bugs = {
/**
* Safari 5 and Safari iOS 4 fail to return to the correct state once a hash is replaced by a `replaceState` call
* https://bugs.webkit.org/show_bug.cgi?id=56249
*/
setHash: Boolean(!History.emulated.pushState && navigator.vendor === 'Apple Computer, Inc.' && /AppleWebKit\/5([0-2]|3[0-3])/.test(navigator.userAgent)),
/**
* Safari 5 and Safari iOS 4 sometimes fail to apply the state change under busy conditions
* https://bugs.webkit.org/show_bug.cgi?id=42940
*/
safariPoll: Boolean(!History.emulated.pushState && navigator.vendor === 'Apple Computer, Inc.' && /AppleWebKit\/5([0-2]|3[0-3])/.test(navigator.userAgent)),
所以我猜你的决定取决于你是否关心 Safari 5 和 Safari IOS 4。