本文介绍了如何从nsIDOMWindow获取Tab?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里的Firefox扩展开发noob。有没有办法从给定的nsIDOMWindow中找到Tab对象? let wm = Cc ['@ mozilla.org/appshell/窗口介体; 1' ]的getService(Ci.nsIWindowMediator);
$ b $ var windowListener =
{
onOpenWindow:function(aWindow)
{
//等待窗口完成加载
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)
{
//如何查找标签?
}
},false);
},
}
wm.addListener(windowListener);
尝试在MDN上查找文档没有运气,mozilla #extdev频道也没给我回应:(b / b)
解决方案
要获取当前标签,您可以执行以下操作:
domWindow.gBrowser.selectedTab
您可以使用的标签:
domWindow.gBrowser.tabContainer
在这里您可以使用方法来选择一个特定的索引,等等。
您可以在,和
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 :(
解决方案
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
这篇关于如何从nsIDOMWindow获取Tab?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!