我正在制作网页,但找不到解决问题的答案。
我正在使用window.history.pushstate和onpopstate事件,这是我的代码:
changeContent = function(href) {
window.history.pushState({}, '', href);
if (href == "/") {
$('#main').load('main.html');
} else {
$('#main').html('<iframe id="gallery" src="photos'+href+'/index.html"></iframe>');
}
};
$(window).on("popstate", function(e) {
changeContent(location.pathname);
});
$(document).on("click", ".galleryLink", function() {
var href = $( this ).attr( "href" );
changeContent(href)
return false;
});
即:谷歌页面 -> 我的主页 -> 图库 -> 返回按钮 -> 我的主页 -> 返回按钮 -> 我的主页 -> 返回按钮 -> 我的主页。
发生了什么?