Here is a quick tip on how you can create a new tab that opens to a specified URL via a FireFox extension:
var myUrl = "http://mesh.typepad.com";
var tBrowser = document.getElementById("content");
var tab = tBrowser.addTab(myUrl);
Post any improvements and / or tips in the comments.
fyi, if you want the new tab to add focus, then add this line to the end of the code snippet:
tBrowser.selectedTab = tab;
mike chambers
Posted by: mike chambers | November 30, 2004 at 10:13 AM
Hi,
Since you know which tab your created, is there a way to use that tab to open a document without selecting that tab? Also, is there a way to check if the tab still exists?
Thanks for your help,
Keith
Posted by: Keith | December 01, 2004 at 07:23 PM
Yes. The tab will automatically open the URL in the background.
If you want to open a different url, try this:
var uri = "http://mesh.typepad.com";
tBrowser.getBrowserForTab(tab).loadURI(uri);
that should do it.
mike chambers
Posted by: mike chambers | December 02, 2004 at 11:19 PM
I'm just a beginner on all this, and I was trying to make Firefox do that from a sidebar.
Turns out (after much banging on the wall on my part) that, as it was a separate document, and the root element wasn't a browser but a page, getElementById("content") doesn't work.
In that case, just replace that line with:
var tBrowser = top.document.getElementById("content");
Being a XUL/DOM n00b is hard on your nerves. :-)
Or am I doing something wrong? =/
Posted by: Antonio | September 13, 2005 at 12:17 PM
show HTML in new tab
addTab only accepts URLs, not HTML, but you can cheat and convert a URL
to HTML something like this:
var url = "data:text/html;charset=UTF-8," + encodeURIComponent(html);
getBrowser().addTab(url);
Posted by: Another Bit Of Info | August 31, 2006 at 09:51 AM