我已經從https://github.com/browserstate/history.js下載了zip,然後在我的web應用程序中上傳browserstate-history.js-e84ad00 \ scripts \ uncompressed \ history.js。我正在使用html來測試這個。以下是保存在html中的腳本。無法使用History.js實現歷史記錄
<script type="text/javascript">
var count=0;
$(document).ready(function(){
$("#change").click(function(){
count=count+1;
$.ajax({
url: "fetch.html",
cache: false,
dataType: "html",
success: function(responseHTML){
wrappedResponseHTML = "<div id='responseTextWrapperDiv'>" + responseHTML + "</div>";
$("#data").html(($(wrappedResponseHTML).find("#toggle")).html());
history.pushState(document.getElementById("data").innerHTML, "", "?page="+count,"");
}
});
});
$("#change2").click(function(){
count=count+1;
$.ajax({
url: "fetch2.html",
cache: false,
dataType: "html",
success: function(responseHTML){
wrappedResponseHTML = "<div id='responseTextWrapperDiv'>" + responseHTML + "</div>";
$("#data").html(($(wrappedResponseHTML).find("#toggle")).html());
history.pushState(document.getElementById("data").innerHTML, "", "?page="+count,"");
}
});
});
});
window.onpopstate = function(event) {
document.getElementById('data').innerHTML=event.state;
if(event.state==null)
{
window.location.href=window.location.href;
}
};</script>
這裏去的身體部位:
<body>
<div id="data">
Landing Page
</div>
<div>
<input type="button" id="change" value="change text" />
<input type="button" id="change2" value="change text 2" />
</div>
<div>
<input type="button" id="back" value="go back" onclick="history.go(-1);"/>
</div></body>
內部ID爲 「數據」 格中的文本是用AJAX改變。這在Mozilla 15.0.1中工作正常,但是當我在IE 8中測試它時,歷史功能不起作用,我不回到以前的狀態。相反,我要回到上一頁,它調用了我的html。在其中一個論壇中,建議的解決方案是包括我已經包含的History.js。還有什麼我錯過了嗎?
通過向我的html添加Doctype來解決此問題。 :) – nevin