History.js无法在Internet Explorer中运行

Wil*_*lic 7 html javascript jquery history.js pushstate

我试图让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>
Run Code Online (Sandbox Code Playgroud)

不知道我做错了什么,但它肯定不适用于IE8或IE9.它确实可以在Firefox中运行,但这可能是因为Firefox实际上支持history.pushstate.任何帮助表示赞赏

Red*_*a P 1

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

参考这个