私は一つの質問を持っており、それが中でどのように私は知ることができる、ということだ、履歴API html5、ユーザーが次回/後ろのブラウザボタンをクリックしたときを知る方法は?
を私はHTML5履歴APIに精通取得していますが、私は互換性を拡張するためにhistory.jsを使用しています:これは私です
History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
var State = History.getState(); // Note: We are using History.getState() instead of event.state
/* Condition here to know if this change is a back or next button, and wich one?? */
});
「全体」コード...
var the = this;
var History = window.History;
if (!History.enabled) {
return false;
}
/* Store the initial content*/
History.replaceState({
content: $('#main').html()
}, document.title, document.location.href);
/* Bind to StateChange Event */
History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
var State = History.getState(); // Note: We are using History.getState() instead of event.state
//console.log(State);
//History.log(State.data, State.title, State.url);
console.log(history.length);
});
/* triggers */
$(document).on('click','a',function(e){
e.preventDefault();
var href = $(this).attr('href');
var title = $(this).text();
if(href == '#')
href = title;
$.get('portfolio.html',function(data, response){
var html = $(data).find('#main-content').html();
//console.log(html);
$('#ajax-load').html(html);
History.pushState({ content: html}, title, href);
$('#ajax-load').css({ position:'absolute',
right: -$(window).width(),
top: the.header.height(),
width: $(window).width(),
zIndex:999
}).animate({ right: 0 },300,function(){
console.log($('#main-content').length);
console.log($('#ajax-load').length);
$('#main-content').html(html);
$('#ajax-load').html('');
});
});
});
実際に履歴を確認する必要があるのは、NEXT/BACKボタンのためです。それ以外の場合はアンカーのhrefルール
-EDIT-
基本的に私はあなたが、特に次またはバックかどうかを確認する必要はありません事前
を修正してみてください、テストしていませんが、あなたはこれをチェックアウトしまし質問http://stackoverflow.com/questions/6359327/detect-back-button-click-in-browser –
またはこれ:http://stackoverflow.com/questions/16548141/is-there-a-way-to-何かの方向を指示していますか? - 状態 - 進行中 - 履歴 - js/16630032#16630032 ?? –