我正在开发一个 Firefox 扩展,并且一直在寻找一种在某些条件下自动显示它(使用 JavaScript)的方法,就好像用户单击了图标一样。
我知道这是可能的,因为一些扩展已经做到了(比如 Wanteeed,见下图)
我的 javascript 获取了我想要的所有信息,我知道当我的情况良好时,我现在唯一需要的是一种让我的小扩展程序的“弹出窗口”神奇地出现的方法
我已尽我所能寻找答案,我希望我没有错过现有的帖子,如果我错过了,抱歉,非常感谢您的回答!
最佳答案
您使用的是最新的WebExtensions格式?如果是这样,那么您不能仅以编程方式打开弹出页面,这是出于安全原因。来自 MDN web docs :
When the user clicks the button, the popup is shown. When the user clicks anywhere outside the popup, the popup is closed. The popup can be closed programmatically by calling window.close() from a script running in the popup. However, you can't open the popup programmatically from an extension's JavaScript: it can only be opened in response to a user action.
另一种方法是使用内容脚本将 position:fixed
div 附加到当前页面,然后使用 CSS 对其进行样式设置以匹配弹出窗口样式。这可能就是您引用的扩展正在执行的操作。
关于javascript - 以编程方式显示 Firefox 扩展弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47409723/