https://github.com/browserstate/history.jsからzipをダウンロードしてから、browserstate-history.js-e84ad00 \ scripts \ uncompressed\history.jsをWebアプリケーションにアップロードしました。私はこれをテストするためにhtmlを使用しています。以下は、htmlに保持されているスクリプトです。
<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が「data」のdiv内のテキストは、ajaxを使用して変更されます。これはMozilla15.0.1では正常に機能しますが、IE 8でテストしたところ、履歴機能が機能せず、以前の状態に戻りません。代わりに、htmlと呼ばれる前のページに戻ります。フォーラムの1つで、提案された解決策は、私が含めたHistory.jsを含めることでした。私が見逃しているものは他にありますか?