强制History.js使用哈希URL回退

时间:2012-02-08 16:09:08

标签: javascript html5 history.js

是否可以强制History.js - https://github.com/browserstate/History.js/ - 在浏览器中使用哈希网址 支持HTML5 /历史记录API?

这仅适用于本地测试,如果需要,可以摆弄History.js源。

1 个答案:

答案 0 :(得分:7)

我想为测试目的做同样的事情,最后更新了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
    };
相关问题