0
這是我的代碼來改變其工作history.pushState(),然後單擊後退/前進按鈕
$.ajax({
url: url,
success: function (data) {
$(selector).html(data);
var title = data.match("<title>(.*?)</title>")[1]; // get title of loaded content
window.history.pushState({page : 0} , document.title, window.location.href); // store current url.
window.history.pushState({page : 1} , title, url); // Change url.
document.title = title; // Since title is not changing with window.history.pushState(),
//manually change title. Possible bug with browsers.
window.onpopstate = function (e) {
window.history.go(0);
};
}
});
AJAX負載URL當我點擊回,以前的頁面加載。如果我再次點擊什麼都沒有發生。再一次點擊它將轉到第一頁。一些測試後我發現,也有後退按鈕2相同的頁面,在每個AJAX加載
此外,我需要一個代碼來獲得歷史時,點擊前進按鈕