我正在尝试让 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/