gpt4 book ai didi

javascript - Firefox 不会在转发时触发 popstate 事件

转载 作者:行者123 更新时间:2023-11-28 06:06:10 26 4
gpt4 key购买 nike

使用 History API 处理 ajax 页面。并卡在 Firefox 不触发“popstate”事件的位置:

以下是访问流程(URL):


1.从主页(/)开始
2.访问关于我们(/about-us)
3. 单击返回按钮返回主页 (/)
4.使用F5刷新页面
5. 单击“前进”按钮继续 (/about-us) # 这里 Firefox 没有触发“popstate”,但 Chrome 是

脚本:

$(window).on("popstate", function (e) {
var data = window.history.state;
console.log("State Data:");
console.log(data);
popped_first = true;
...
});

最佳答案

使用pushState来唤醒它。

history.pushState({}, '');
window.onpopstate = function() {
alert(1);
};

关于javascript - Firefox 不会在转发时触发 popstate 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36839110/

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