如何确定 Firefox 中的所有选项卡均已加载?

发布于 2024-11-17 21:52:30 字数 599 浏览 3 评论 0原文

我正在编写一个 Firefox 插件,我需要能够在加载所有选项卡后运行一些代码。

我尝试了类似的方法:

window.addEventListener("load", function(e) { 
   gBrowser.addEventListener("load", function(ee) {
      // code to run after all tabs have loaded

         // thank user for installing my add-on
         alert('Thank you for installing my add-on');

         // add tab to my website
         gBrowser.selectedTab = gBrowser.addTab("http://www.mywebsite.com/");

   }, true);
}, false);

但这不起作用,因为这将在加载后运行每个选项卡的代码。我想等到所有选项卡都加载完毕。我想在用户安装我的附加组件后 Firefox 重新启动时打印一条警报消息。我还想向我的网站添加一个新选项卡。

我该怎么做?

I am writing a Firefox add-on and I need to be able to run some code after all the tabs have been loaded.

I tried something like:

window.addEventListener("load", function(e) { 
   gBrowser.addEventListener("load", function(ee) {
      // code to run after all tabs have loaded

         // thank user for installing my add-on
         alert('Thank you for installing my add-on');

         // add tab to my website
         gBrowser.selectedTab = gBrowser.addTab("http://www.mywebsite.com/");

   }, true);
}, false);

But this does not work because this will run the code for each tab after it is loaded. I want to wait until all of the tabs have loaded. I want to print an alert message when the Firefox restarts after the users installs my add-on. I also want to add a new tab to my website.

How do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久伴你 2024-11-24 21:52:30

我猜你的意思是等到浏览器启动时会话恢复。您可以通过观察者服务收听发送的 sessionstore-windows-restored 通知。像这样的东西:

Cu.import("resource://gre/modules/XPCOMUtils.jsm");
var observer =
{
  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIObserver]),
  observe: function(subject, topic, data)
  {
    observerService.removeObserver(observer, "sessionstore-windows-restored");
    addTabNow();
  }
};

var observerService = Components.classes["@mozilla.org/observer-service;1"]
                                .getService(Components.interfaces.nsIObserverService);
observerService.addObserver(observer, "sessionstore-windows-restored", false);

I guess that you mean to wait until the session is restored when the browser starts up. There is a sessionstore-windows-restored notification sent out that you can listen to via observer service. Something like this:

Cu.import("resource://gre/modules/XPCOMUtils.jsm");
var observer =
{
  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIObserver]),
  observe: function(subject, topic, data)
  {
    observerService.removeObserver(observer, "sessionstore-windows-restored");
    addTabNow();
  }
};

var observerService = Components.classes["@mozilla.org/observer-service;1"]
                                .getService(Components.interfaces.nsIObserverService);
observerService.addObserver(observer, "sessionstore-windows-restored", false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文