问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/17042461/force-html4-fallback-in-history-js