简体   繁体   中英

Force History.js to use hash URL fallback

Is it possible to force History.js - https://github.com/browserstate/History.js/ - to use the hash URLs in a browser which does support HTML5/history API?

This is only for local testing, so fiddling with the History.js source is fine if that's required.

I wanted to do the same thing for testing purposes and ended up updating the following lines in the jquery.history.js library.

Original: ( 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)}

Hack Solution:

m.emulated={pushState:true,hashChange:true}

I'm using the HTML4+HTML5 bundled minified code, but the line corresponds to Line 269 in the history.js uncompressed file. If you are using a different version, the corresponding section is here:

Unminified Original ( 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)
)
};

Hack Solution:

History.emulated = {
    pushState: true,
    hashChange: true
    };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM