Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force html4 fallback in history.js

I can not get the html4Mode option to work for me.

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

To force the fallback I just changed the ajaxify script adding (on DOM ready):

History.options.html4Mode = true;

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

Is there a way to get this working?

like image 392
smarques Avatar asked Jun 11 '13 10:06

smarques


1 Answers

To properly initialize the options for history.js, the options must be set before the script is included on the page. This could look similar to the following:

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

If it is a requirement that the HTML4 flag be set on DOM ready, then you can use the delayInit option in the same way. Just note that you must call History.init() manually when you're 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've successfully used the method demonstrated in the first example. The second I have not tested personally.

like image 67
dasch88 Avatar answered Sep 20 '22 01:09

dasch88