开发者

How do I determine that all tabs have been loaded in 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 installin开发者_C百科g 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?


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜