问题
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