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

stu*_*nik 4 javascript html5 history.js

是否有可能迫使History.js - https://github.com/browserstate/History.js/ -使用哈希的URL在浏览器支持HTML5 /历史API?

这仅适用于本地测试,因此如果需要,可以使用History.js源.

daz*_*ury 7

我想为测试目的做同样的事情,最后更新jquery.history.js库中的以下行.

原文:( 在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)}
Run Code Online (Sandbox Code Playgroud)

黑客解决方案

m.emulated={pushState:true,hashChange:true}
Run Code Online (Sandbox Code Playgroud)

我正在使用HTML4 + HTML5捆绑的缩小代码,但该行对应于history.js未压缩文件中的第269行.如果您使用的是其他版本,则相应的部分位于:

Unminified Original(在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)
)
};
Run Code Online (Sandbox Code Playgroud)

黑客解决方案

History.emulated = {
    pushState: true,
    hashChange: true
    };
Run Code Online (Sandbox Code Playgroud)

  • 针对新读者的headsup,history.js有一个强制使用hashtag的选项 - 来自history.js文档:History.options.html4Mode - 如果为true,将强制HTMl4模式(hashtags) (9认同)