gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 13:13:12 25 4
gpt4 key购买 nike

与 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com