我的網站工作得更快,這要感謝我經過精心修改的一些代碼,但如果瀏覽器的後退/前進按鈕起作用,我會很喜歡。現在,使用下面的代碼,瀏覽器地址欄永遠不會改變。當有人點擊「返回」時,會將其從應用程序中取出。讓我的前進和後退按鈕與ajax一起工作
有沒有通過任何簡單的方法來改變這個瀏覽器的後退/前進按鈕的工作?否則,如果有人能指引我正確的方向。謝謝你的幫助。
$(document).on("ready", function() {
//I want to load content into the '.page-content' class, with ajax
var ajax_loaded = (function (response) {
$(".page-content")
.html($(response).filter(".page-content"));
$(".page-content .ajax").on("click", ajax_load);
});
//the function below is called by links that are described
//with the class 'ajax', or are in the div 'menu'
var history = [];
var ajax_load = (function (e) {
e.preventDefault();
history.push(this);
var url = $(this).attr("href");
var method = $(this).attr("data-method");
$.ajax({
url: url,
type: method,
success: ajax_loaded
});
});
//monitor for clicks from menu div, or with
//the ajax class
//why the trigger?
$("#menu a").on("click", ajax_load);
$(".ajax").on("click", ajax_load);
$("#menu a.main").trigger("click");
});
是的。 History.js - 它推動瀏覽器狀態,並允許前後移動 –