Force html4 recovery in history.js

I cannot get the html4Mode parameter html4Mode work for me.

I am using an ajaxify script ( https://github.com/browserstate/ajaxify ) in a very simple two page application. Everything works fine in html5-compatible browsers, but if I want to force the html4 reserve for testing purposes nothing changes, it seems that the history ignores the parameters and continues to use html5 push state urls.

To force the backup, I just changed the add ajaxify script (to DOM ready):

 History.options.html4Mode = true; 

(I am using v1.8b1 jquery html4 + 5 bundle script)

Is there any way to make this work?

+6
source share
1 answer

To properly initialize the parameters for history.js, the parameters must be set before the script is included in the page. It might look something like this:

 <script type="text/javascript" language="javascript"> window.History = { options: { html4Mode: true} }; </script> <script src="/scripts/jquery.history.min.js" type="text/javascript"></script> 

If you want the HTML4 flag to be set in the DOM, you can use the delayInit parameter in the same way. Just keep in mind that you must call History.init () manually when you are ready:

 <script type="text/javascript" language="javascript"> window.History = { options: { delayInit: true} }; </script> <script src="/scripts/jquery.history.min.js" type="text/javascript"></script> ... <script type="text/javascript" language="javascript"> $(document).ready(function () { var userInput = true; //some code gathering user input or something window.History.options.html4Mode = userInput; window.History.init(); ); </script> 

Sources: https://github.com/browserstate/history.js/pull/195 https://github.com/browserstate/history.js/issues/303

Note. I successfully used the method demonstrated in the first example. I have not personally tested the second one.

+9
source

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


All Articles