3

History.js 现在是否比 HTML5 提供任何实质性的优势window.history?我们对支持/退回到 HTML4 hashbang URL 不感兴趣。

History.js不支持锚点pushState(),而支持window.history。我们需要这个特性,所以如果没有很大的理由window.history在 HTML5-only 模式下使用 History.js 而不是原生,我们宁愿选择后者。

4

1 回答 1

3

是的 - 他们在他们的网站上说:

为所有 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。

于 2013-05-03T15:22:40.663 回答