我正试图让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。感谢您的帮助。