[Project_owners] Enumerating tab URLs in Mozilla/Seamonkey/Netscape

HJ bugs4hj at netscape.net
Wed Jul 13 21:47:09 EDT 2005


Eric Jung wrote:
> Hi,
> I have this code which works great in FF, but not in
> Mozilla/Seamonkey/Netscape. I'm trying to get a list of URLs of all
> open tabs in all open browsers. Anyone know how to do it for non-FF
> browsers?
> 
> Thanks in advance,
> Eric Jung
> 
>   var urls = new Array();
>   var wm =
>     Components.classes["@mozilla.org/appshell/window-mediator;1"]
>     .getService(Components.interfaces.nsIWindowMediator);
>   var browserEnumerator = wm.getEnumerator("navigator:browser");
> 
>   while (browserEnumerator.hasMoreElements()) {
>     var browserInstance =
>       browserEnumerator.getNext().document.getElementById("content");
>     // Check each tab of this browser instance
>     var numTabs = browserInstance.mPanelContainer.childNodes.length;
>     for (var index=0; index<numTabs; index++) {
>       var currentTab = browserInstance.getBrowserAtIndex(index);
>       urls.push(currentTab.currentURI.spec);
>     }
>   } 

You should be able to use browserInstance.gBrowser.browsers for this. 
Please note that there is no method getBrowserAtIndex in Mozilla.

/HJ


More information about the Project_owners mailing list