gpt4 book ai didi

javascript - 后退按钮只能工作一次

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:06:32 25 4
gpt4 key购买 nike

我正在处理我的页面,但找不到我的问题的答案。

我正在使用 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;
});

google 页面 -> 我的主页 -> 图库 -> 后退按钮 -> 我的主页 -> 后退按钮 -> 我的主页 -> 后退按钮 -> 我的主页

这是怎么回事?

最佳答案

知道了!

线路:

window.history.pushState({}, '', href);

应该在里面

$(document).on("click", ".galleryLink", function()

我把它放在里面

changeContent = function(href)

这是我的错...:-)

关于javascript - 后退按钮只能工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21445178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com