Implementation of History.js HTML4

The jQuery plugin HISTORY.js ( https://github.com/browserstate/History.js/ ) provides a function for implementing push pages in HTML5 format, and in the case of an unsupported browser, you should be able to implement the HTML4 hash function. The / README documentation file describes usage as follows:

var History = window.History; // Note: We are using a capital H instead of a lower h if ( !History.enabled ) { // History.js is disabled for this browser. // This is because we can optionally choose to support HTML4 browsers or not. return false; } 

As you can see, the documentation explains the use of the HISTORY.js plugin up to the HTML5 level and does not explain the use of HTML4 support.

However, in the "Download and Install" section of the documentation, it reads:

 5. Include History.js <script src="http://www.yourwebsite.com/history.js/scripts/compressed/history.js">/script> <script src="http://www.yourwebsite.com/history.js/scripts/compressed/history.html4.js"></script> 

The instructions here may indicate that HTML4 hashtag support is automatic, but the instructions on the use page suggest that it must be done manually; which, I believe, actually takes place.

I cannot find any additional documentation on the implementation of the HTML4 hash function. Please help me figure this out.

+6
source share
1 answer

Well, maybe the problem is that you did not use History.js correctly (that I have a problem too). Basically, to use History.js correctly, you have to do something like:

 // Register navigation click handlers where you will load Ajax content $( window ).on( 'click', 'a.ai1ec-load-view', handle_click_on_link_to_load_view ); // Bind to the statechange event $( window ).bind( 'statechange', handle_state_change ); // When the state changes, load the corresponding view var handle_state_change = function( e ) { var state = History.getState(); load_view( state.url, 'json' ); }; // When clicking on a link you want to load, trigger statechange by changing state var handle_click_on_link_to_load_view = function( e ) { e.preventDefault(); History.pushState( { target :this }, null, $( this ).attr( 'href' ) ); }; 

Before doing this, I did not listen to statechange , and I just used pushState () in the link handler.

If you do it this way, there is no need to encode a backup, it will work in html4 browsers too (and bookmarks from html4 browsers will work as expected)

+1
source

Source: https://habr.com/ru/post/895836/


All Articles