$(function() {
var $article = $("article"),
init = function() {
// Do this when a page loads.
},
ajaxLoad = function(html) {
document.title = html
.match(/<title>(.*?)<\/title>/)[1]
.trim();
init();
};
init();
$(document).on("click", "a, area", function() {
var href = $(this).attr("href");
history.pushState({}, '', href);
$article.load(href + " article>*", ajaxLoad);
return false;
});
});
非常感谢您的帮助!
init()之后添加了这一点
并且效果完美!
$(window).on("popstate", function(e) {
if (e.originalEvent.state !== null) {
loadPage(location.href);
}
});
loadPage = function(href) {
$article.load(href + " article>*", ajaxLoad);
};