history.js を使用してpushState
、ajax でコンテンツを変更しながら使用するページの URL を変更しています。
私の問題は、最初にアクセスしたページで [戻る] ボタンが機能しないことです。コンテンツが保存されていないか、コンテンツの取得に使用した情報が保存されていません。
動作する初期化を呼び出すと、pushState
どういうわけかそのページの 2 つのエントリが表示されます。だから、私が戻ってきたとき、私は元のメインページにたどり着くためにもう一度戻って行かなければなりません. それが理にかなっているのかどうかはわかりません。ここで私の特定のケースに関連するものは何も見つからないようです。
$(function() {
var History = window.History;
if ( !History.enabled ) {
return false;
}
if($.url().attr('fragment')){
var url = $.url().attr('fragment').split("-");
}else{
var url = $.url().attr('path').split("-");
}
photo_ajax(url[3],url[2],url[4]); //perform ajax content update
//initialize first page but doesn't quite work as it creates two entries
//History.pushState({pho_id:url[3],per_id:url[2],a_id:url[4]}, "Viewing Photo", $.url().attr('path'));
History.Adapter.bind(window,'statechange',function() {
var State = History.getState();
photo_ajax(State.data.pho_id,State.data.per_id,State.data.a_id);
});
});
$(document).ready(function(){
$(document).on('click', '[id^="dopho_"]', function(event){
var id = $(this).attr("id").split('_');
event.preventDefault();
History.pushState({pho_id:id[1],per_id:id[2],a_id:id[3]}, "Viewing Photo", $(this).attr('href'));
});
});