History.js在Internet Explorer中无法工作

7

我正试图让history.js在Internet Explorer中工作,因为我需要history.pushState()函数。我已经阅读了GitHub上的说明(https://github.com/browserstate/History.js/),并尝试实现它,但没有成功。

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <!-- jQuery --> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> 
    <!-- History.js --> 
    <script defer src="http://balupton.github.com/history.js/scripts/bundled/html4+html5/jquery.history.js"></script> 
    <script type="text/javascript">
        function addHistory(){

            // Prepare
            var History = window.History; // Note: We are using a capital H instead of a lower h

            // Change our States
            History.pushState(null, null, "mylink.html"); 
        }      
    </script>
</head>
<body>
    <a href="mylink.html">My Link</a>
    <a href="otherlink.html">Other Link</a>
    <button onclick="addHistory()" type="button">Add History</button>   
</body>

我不确定自己做错了什么,但在IE8或IE9上肯定无法工作。它在Firefox中可以工作,但这可能是因为Firefox本身支持history.pushstate。感谢您的帮助。


1
它在其他地方工作吗,还是你只尝试了IE? - Kyeotic
你尝试过IE的哪个版本或所有版本? - Chris Pratt
我已经尝试过IE8和IE9,很抱歉之前没有提到。它在Firefox中可以工作,但这可能是因为Firefox默认支持history.pushstate? - user731483
你到底希望它做什么?History.js 应该可以在大多数浏览器中工作,甚至是 IE,但它在 HTML4 和 HTML5 兼容的浏览器中的工作方式是不同的。 - jgivoni
1个回答

1
在第二个 <script> 标签中删除单词 defer
因为,如果你提到那个单词,那意味着推迟。(如果你想要保存它以减少页面渲染的阻塞,请勿删除它)。IE 对此非常严格,这就是你遇到问题的原因。希望能帮到你。
参考 this

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接