html - History.js 与 window.history 仅用于 HTML5 模式

标签 html browser-history pushstate history.js html5-history

与 HTML5 的 window.history 相比,History.js 现在有什么实质性的优势吗?我们对支持/回退到 HTML4 hashbang URL 不感兴趣。

History.js doesn't support anchors in pushState() ,而 window.history 会。我们需要此功能,因此如果没有充分理由在纯 HTML5 模式下使用 History.js 而不是 native window.history,我们宁愿选择后者。

最佳答案

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

Provide a cross-compatible experience for all HTML5 Browsers (they all implement the HTML5 >History API a little bit differently causing different behaviours and sometimes bugs - >History.js fixes this ensuring the experience is as expected / the same / great throughout >the HTML5 browsers)

这些差异很小,谷歌搜索不足以找到它们 - 我不得不查看源代码 - 似乎主要的差异是修复 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。

关于html - History.js 与 window.history 仅用于 HTML5 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16335791/

相关文章:

jquery - 有什么方法可以确定 HTML 选择当前是否打开?

javascript - 如何检测与曲线的碰撞

javascript - 更改 window.location.hash 在历史记录中创建条目但不影响 chrome 后退按钮

javascript - 网站是历史上的第一项吗?

php - 你如何处理 jQuery 中的后退按钮?

jquery - 如何使用 JavaScript 历史记录 API

javascript - Backbone.js PushState 真

php - 无法连接数据库和处理 POST 请求

javascript - 使用 jquery 在移动平板电脑和桌面分辨率中显示不同尺寸的图像

javascript - 如何通过js启用/禁用浏览器历史记录