Reputation: 161
How can I get the URl of the next tab on Firefox? I am using this now:
//The browser object points to the new tab which I capture using the
//'TabOpen' Event
var browser = gBrowser.getBrowserForTab(event.target);
//From where can I get the URL of this new tab ? Also, how to I get
//the Title of this new Tab
Upvotes: 2
Views: 4088
Reputation: 32063
First search google for "getBrowserForTab" to see what kind of object it returns. You'll see a page with examples as the first hit, and the reference page as the second hit. The latter is what we're looking for. It says:
[getBrowserForTab( tab )] Returns a browser for the specified tab element.
Follow the link for browser to see what properties and methods this object has.
You'll see it has a contentTitle property ("This read-only property contains the title of the document object in the browser."), which answers the second part of your question.
Similarly you see it has a currentURI property which returns "the currently loaded URL". The returned object is an nsIURI
, to get its string representation you need to use currentURI.spec
, as described in the nsIURI documentation.
So to sum up:
var title = browser.contentTitle; // returns the title of the currently loaded page
var url = browser.currentURI.spec; // returns the currently loaded URL as string
You could also just get the window
/document
objects of the content page via browser.contentWindow
/browser.contentDocument
and get the title/URL (and other things) using the APIs you would use in a regular web page.
Upvotes: 14