How to get Tab from nsIDOMWindow?

梦想的初衷 提交于 2019-12-24 02:58:07

问题


A noob at firefox extension development here. Is there a way to find Tab object from a given nsIDOMWindow?

let wm = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);

var windowListener =
{
  onOpenWindow: function(aWindow)
  {
    // Wait for the window to finish loading
    let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);

    domWindow.addEventListener("load", function()
    {
      domWindow.removeEventListener("load", arguments.callee, false);

      if (domWindow.document.documentElement.getAttribute("windowtype") == "navigator:browser")
      {

        // how do I find tabs?

      }
    }, false);
  },
}

wm.addListener(windowListener);

Been trying to find the documentation on MDN with no luck, mozilla #extdev channel gives me no response either :(


回答1:


To get the current tab you can do:

domWindow.gBrowser.selectedTab

To get the set of all tabs you can use:

domWindow.gBrowser.tabContainer 

In here you can use tabs methods to select a specific index, etc. You can see more information in tabbrowser - XUL, Tabbed browser - Code Snippets and



来源:https://stackoverflow.com/questions/19310570/how-to-get-tab-from-nsidomwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!