Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting URIs of open tabs

14 views
Skip to first unread message

Matthew Smith

unread,
Nov 6, 2006, 9:35:12 PM11/6/06
to dev-te...@lists.mozilla.org
Hi

I am trying to take a snapshot of all tabs in Firefox, but am having
problems working out how to access the URIs of all the pages.

So far, I have managed to get the labels of all the tabs:

var tabs=gBrowser.tabContainer.childNodes;
for(var i=tabs.length - 1; i>=0; i--)
{
alert(tabs[i].getAttribute('label'));
}

How do I get the URIs? Elements of type tab inherit the uri attribute
from the XUL element, but it just comes up blank.

Cheers

M

--
Matthew Smith
IT Consultancy & Accessible Web Application Development
Business: http://www.kbc.net.au/
Personal: http://www.smiffysplace.com/
LinkedIn: http://www.linkedin.com/in/smiffy

Neil

unread,
Nov 7, 2006, 6:43:08 AM11/7/06
to
Matthew Smith wrote:

>I am trying to take a snapshot of all tabs in Firefox, but am having problems working out how to access the URIs of all the pages.
>
>

You should look at the way the "Bookmark this group of tabs" code works
(sorry I don't have a link).

--
Warning: May contain traces of nuts.

Matthew Smith

unread,
Nov 7, 2006, 11:44:39 PM11/7/06
to dev-te...@lists.mozilla.org
Quoth Neil at 11/07/06 22:13...

> Matthew Smith wrote:
>
>>I am trying to take a snapshot of all tabs in Firefox, but am having problems working out how to access the URIs of all the pages.
>>
>>
> You should look at the way the "Bookmark this group of tabs" code works
> (sorry I don't have a link).

I was unable to find it in the browser source, although found a few
clues which, with DOM inspector got the answer:

// Get browsers object
var browsers=document.getElementById('content').browsers;
var numBrowsers=browsers.length;

for (var i=0; numBrowsers>i; i++)
{
var thisURI=browsers[i].currentURI.spec;
// do something with it.

Neil

unread,
Nov 8, 2006, 5:31:29 AM11/8/06
to
Matthew Smith wrote:

>// Get browsers object
>var browsers=document.getElementById('content').browsers;
>var numBrowsers=browsers.length;
>
> for (var i=0; numBrowsers>i; i++)
> {
> var thisURI=browsers[i].currentURI.spec;
> // do something with it.
> }
>
>

You can get the titles too using .contentTitle which would save you a step.

Matthew Smith

unread,
Nov 8, 2006, 6:13:14 PM11/8/06
to dev-te...@lists.mozilla.org
Quoth Neil at 11/08/06 21:01...

>>// Get browsers object
>>var browsers=document.getElementById('content').browsers;
>>var numBrowsers=browsers.length;
>>
>> for (var i=0; numBrowsers>i; i++)
>> {
>> var thisURI=browsers[i].currentURI.spec;
>> // do something with it.
>> }
>>
> You can get the titles too using .contentTitle which would save you a step.

In this instance, I just need the URIs. This is a new part of my
WebSticky[1] project, similar to "bookmark group of tabs". We retrieve
the URIs of all open tabs, turn them into an XML string, then POST it to
the server. We can then reverse the process to restore the snapshot.

As this is a client/server model, one can snapshot the tabs on one
computer (say work), then restore them on another computer (say home).

Cheers

M


1 - http://www.websticky.net

0 new messages