gpt4 book ai didi

javascript - 在 Facebook 的 Chrome 扩展中使用 onpopstate

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

我正在尝试为 facebook 创建一个 Chrome 插件,我正在使用 onpopstate 事件来检查用户何时转到另一个页面。唯一的问题是 onpopstate 不会触发。

这是我正在使用的(简单的)代码:

window.onpopstate = function() { console.log('pop'); };

这是问题的屏幕:

code test in console

如您所见,调用了 pushState 代码,但没有调用 onpopstate 监听器。

你知道这里发生了什么吗?

最佳答案

@enhzflep 的回答在上面的评论中,不是很明显。来自 MDN :

Calling history.pushState() or history.replaceState() won't trigger a popstate event. The popstate event is only triggered by performing a browser action, such as clicking on the back button (or calling history.back() in JavaScript), when navigating between two history entries for the same document.

换句话说,在这种情况下不应触发 onpopstate 事件。

关于javascript - 在 Facebook 的 Chrome 扩展中使用 onpopstate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13113413/

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