Javascript 后退按钮只工作一次
我正在处理我的页面,找不到问题的答案 我正在使用window.history.pushstate和onpopstate事件,下面是我的代码:Javascript 后退按钮只工作一次,javascript,jquery,back-button,pushstate,Javascript,Jquery,Back Button,Pushstate,我正在处理我的页面,找不到问题的答案 我正在使用window.history.pushstate和onpopstate事件,下面是我的代码: changeContent = function(href) { window.history.pushState({}, '', href); if (href == "/") { $('#main').load('main.html'); } else { $('#main').html('<iframe id="ga
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;
});
changeContent=function(href){
window.history.pushState({},,,href);
如果(href==“/”){
$('#main').load('main.html');
}否则{
$('#main').html('');
}
};
$(窗口).on(“popstate”,函数(e){
changeContent(location.pathname);
});
$(document).on(“click”,“.galleryLink”,函数(){
var href=$(this.attr(“href”);
更改内容(href)
返回false;
});
i、 e
谷歌页面->我的主页->图库->后退按钮->我的主页->后退按钮->我的主页->后退按钮->我的主页
发生了什么事?这里说,jQuery在捕获
popstate
事件时遇到问题,您应该使用本机onpopstate
但是我想知道为什么它只工作一次?明白了强> 行: 应该在里面
$(document).on("click", ".galleryLink", function()
我把它放进去了
changeContent = function(href)
这是我的错…:-) 我的jQuery捕捉效果很好,我找到了一个答案,但现在无法回答我自己的问题(声誉很低)@YaPKnn啊,是的,最后也得到了,changecontent也在popstate上被调用了。是的。我没有使用jQuery,也有同样的问题。我不能把一个函数作为第三个参数,你是怎么解决这个问题的?
changeContent = function(href)