Created
February 3, 2012 17:46
-
-
Save findzen/1731354 to your computer and use it in GitHub Desktop.
History.js HTML4 / HTML5 parity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // save hash value for HTML5 browsers arriving to site via HTML4 hashed url | |
| // this should be done before $(document).ready and History.js is loaded | |
| window.initHash = window.location.hash; | |
| $(document).ready(function() { | |
| var baseURL = History.getBaseUrl(), | |
| currentURL = History.getState().url, | |
| relativeURL = currentURL.replace( baseURL, '' ); | |
| if ( !Modernizr.history && currentURL !== baseURL ) { | |
| // if browser doesn't support HTML5 history and this isn't the root url, | |
| // redirect to the root url + hash | |
| document.location.href = baseURL + '#./' + relativeURL; | |
| return; | |
| } else if ( Modernizr.history && window.initHash.length ) { | |
| // if this browser supports HTMLS history and the initial url included a hash, | |
| // load the content via ajax (assumes load method is defined elsewhere) | |
| load( History.getState().url ); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment