Javascript 使用History.js back按钮不会';不行?
我在这里使用History.js 这就是我目前拥有的:Javascript 使用History.js back按钮不会';不行?,javascript,ajax,history.js,Javascript,Ajax,History.js,我在这里使用History.js 这就是我目前拥有的: var History = window.History; if (History.enabled) { // set initial state for first page that is loaded var State = History.getState(); History.pushState({urlPath: window.location.pathname},
var History = window.History;
if (History.enabled) {
// set initial state for first page that is loaded
var State = History.getState();
History.pushState({urlPath: window.location.pathname}, $("title").text(), State.urlPath);
}
else {
return false;
}
// content update and back/forward button handler
History.Adapter.bind(window, 'statechange', function(){
var s = History.getState();
History.log(s.data, s.title, s.url);
// update view based on load type
OnLoadPageByURL(s.data.urlPath);
});
// navigation link handler(s)
$('body').on('click', 'a', function(e){
e.preventDefault();
var load = $(e.currentTarget).data('load');
var urlPath = $(this).attr('href');
var title = $(this).text();
History.pushState({ load: load, urlPath: urlPath }, title, urlPath);
});
一切似乎都正常工作,但“后退”按钮似乎工作不正常?我做错了什么?请您提供有关
OnLoadPageByURL(s.data.urlPath)的详细信息代码>?哦,对不起。我实际上解决了这个问题。上面的代码是完美的。我在其他地方遇到了一个问题,导致了这个问题。谢谢你查看这篇文章。不客气,我很高兴你找到了。