在history.js中强制html4回退 [英] Force html4 fallback in history.js

查看:186
本文介绍了在history.js中强制html4回退的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能得到 html4Mode 选项为我工作。



我正在使用ajaxify脚本 https://github.com/browserstate/ajaxify )在一个非常简单的两页应用程序。一切都可以在html5能力的浏览器中正常工作,但如果我想强制html4的后备用于测试目的没有任何变化,似乎历史忽略了选项,并继续使用html5推状态URL。



  History.options.html4Mode = 

要强制回退我只是更改了ajaxify脚本添加(在DOM准备好)真正;

(我正在使用v1.8b1 jquery html4 + 5软件包脚本)



有没有办法让这个工作?

解决方案

正确初始化历史选项.js,必须在脚本包含在页面之前设置选项。这可能类似于以下内容:

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

如果需要在DOM上设置HTML4标志,那么可以使用delayInit选项以相同的方式。只需要注意,准备就绪时您必须手动调用History.init():

 < script type =text / javascriptlanguage =javascript> 
window.History = {options:{delayInit:true}};
< / script>
< script src =/ scripts / jquery.history.min.jstype =text / javascript>< / script>
...
< script type =text / javascriptlanguage =javascript>
$(document).ready(function(){
var userInput = true;
//某些代码收集用户输入或某事
window.History.options.html4Mode = userInput ;
window.History.init();
);
< / script>

资料来源:
https://github.com/browserstate/history.js/pull/195
https://github.com/browserstate/history.js/issues/303



注意:我已经成功使用第一个例子中所示的方法。第二个我没有亲自测试。


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?

解决方案

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.

这篇关于在history.js中强制html4回退的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆