参数是context文档或元素。从那里到窗户并不难:
var {Ci} = require("chrome");
if (!(context instanceof Ci.nsIDOMWindow))
{
// If this is an element, get the corresponding document
if (context instanceof Ci.nsIDOMNode && context.ownerDocument)
context = context.ownerDocument;
// Now we should have a document, get its window
if (context instanceof Ci.nsIDOMDocument)
context = context.defaultView;
else
context = null;
}
// If we have a window now - get the tab
if (context)
{
var tabsLib = require("tabs/tab.js");
return tabsLib.getTabForWindow(context.top);
}
else
return null;
供参考:Node,Document,window。