【发布时间】:2012-02-08 16:09:07
【问题描述】:
是否可以强制 History.js - https://github.com/browserstate/History.js/ - 在确实支持 HTML5/history API 的浏览器中使用哈希 URL?
这仅用于本地测试,因此如果需要,可以修改 History.js 源代码。
【问题讨论】:
标签: javascript html history.js
是否可以强制 History.js - https://github.com/browserstate/History.js/ - 在确实支持 HTML5/history API 的浏览器中使用哈希 URL?
这仅用于本地测试,因此如果需要,可以修改 History.js 源代码。
【问题讨论】:
标签: javascript html history.js
我想为测试目的做同样的事情,最终更新了 jquery.history.js 库中的以下行。
原文:(View on GitHub)
m.emulated={pushState:!Boolean(a.history&&a.history.pushState&&a.history.replaceState&&!/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i.test(e.userAgent)&&!/AppleWebKit\/5([0-2]|3[0-2])/i.test(e.userAgent)),hashChange:Boolean(!("onhashchange"in a||"onhashchange"in d)||m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<8)}
破解解决方案:
m.emulated={pushState:true,hashChange:true}
我正在使用 HTML4+HTML5 捆绑的缩小代码,但该行对应于 history.js 未压缩文件中的第 269 行。如果您使用的是不同的版本,相应的部分在这里:
未缩小的原件 (View on GitHub):
History.emulated = {
pushState: !Boolean(
window.history && window.history.pushState && window.history.replaceState
&& !(
(/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i).test(navigator.userAgent) /* disable for versions of iOS before version 4.3 (8F190) */
|| (/AppleWebKit\/5([0-2]|3[0-2])/i).test(navigator.userAgent) /* disable for the mercury iOS browser, or at least older versions of the webkit engine */
)
),
hashChange: Boolean(
!(('onhashchange' in window) || ('onhashchange' in document))
||
(History.isInternetExplorer() && History.getInternetExplorerMajorVersion() < 8)
)
};
破解解决方案:
History.emulated = {
pushState: true,
hashChange: true
};
【讨论】:
# 版本工作?