2009-09-01 34 views
1

在Firefox 3.5我得到一个参考主窗口侧边栏:FF 3.5扩展:window.title是“未定义”

var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) 
       .getInterface(Components.interfaces.nsIWebNavigation) 
       .QueryInterface(Components.interfaces.nsIDocShellTreeItem) 
       .rootTreeItem 
       .QueryInterface(Components.interfaces.nsIInterfaceRequestor) 
       .getInterface(Components.interfaces.nsIDOMWindow); 

然后,mainWindow.title是不确定的(这在Firefox 3.0) 。

我也试过:

mainWindow.getBrowser().selectedBrowser.contentWindow.title (also undefined) 

,它可能是值得注意的是,

mainWindow.getBrowser().selectedBrowser.contentWindow.location.href 

返回正确的URL。

谢谢! 诺亚

回答

1

我认为你真正想要的是mainWindow.content.document.title。 title属性存在于文档中,而不是窗口,并且应该在3.0及更高版本中工作。

0

它在being deprecated since 2004之后在bug 450977中被移除。

如果我读到的错误是正确的,那么正确的替换是document.title

+0

如果你的脚本在主窗口browser.xul中运行,那么'document.title'就可以工作。我不希望它从侧边栏工作,但我没有尝试,所以我不知道。 – MatrixFrog

+0

是的,“document.title”会返回侧边栏的标题而不是真正的标题,但是OP明确知道如何从侧边栏上下文到browser.xul窗口。 – Nickolay