views:

158

answers:

2

From a sidebar in Firefox 3.5 I am getting a reference to the main window with:

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

Then, mainWindow.title is undefined (this works in Firefox 3.0).

I've also tried:

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

and it might be worth noting that

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

returns the correct URL.

Thanks! Noah

+1  A: 

I think what you really want is mainWindow.content.document.title. The title attribute exists on a document, not a window and should work in 3.0 and beyond.

sdwilsh
A: 

It was removed in bug 450977 after being deprecated since 2004.

If my reading of the bugs is correct, the correct replacement is document.title.

Nickolay
`document.title` works if your script is running in the main window, `browser.xul`. I wouldn't expect it to work from a sidebar but I haven't tried so I don't know.
MatrixFrog
Yes, "document.title" would return the sidebar's title instead of the real title, but the OP clearly knows how to get from the sidebar context to the browser.xul window.
Nickolay