javascript - History.js 在 Internet Explorer 中不工作

标签 javascript jquery html pushstate history.js

我正在尝试让 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。感谢任何帮助

最佳答案

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

引用this

关于javascript - History.js 在 Internet Explorer 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11352651/

相关文章:

javascript - 无法使用 jQuery clockpicker 插件?

javascript - jQuery Slider(div 粘在一边)

javascript - jQuery - 在 .css() 方法中组合变量和字符串

javascript - 仅在 1 行上显示文本而不破坏单词并以省略号终止

javascript - RegExp 范围乱序且模式复杂

javascript - 更改按钮并在悬停时添加表单

javascript - functioninitialize() 和 xmlhttp.onreadystatechange = function() 事件顺序

javascript - 使用Jquery删除div之间的div

HTML/CSS 背景问题

html - 从单个 png 图像获取图标