Jump to content
xisto Community
Sign in to follow this  
clemen

Opening New Tabs With Javascript

Recommended Posts

I just spent a couple of hours trying to figure out how to open new tabs from a Firefox sidebar. I found lots of different suggestions but none worked. Well finally I found this and it works.

 

var browser = top.document.getElementById("content");

var tab = browser.addTab("https://www.google.de/?gfe_rd=cr&ei=BwkjVKfAD8uH8QfckIGgCQ&gws_rd=ssl;);

 

An even better way of doing it is through:

 

const kWindowMediatorContractID = "@mozilla.org/appshell/window-mediator;1";

const kWindowMediatorIID = Components.interfaces.nsIWindowMediator;

const kWindowMediator = Components.classes[kWindowMediatorContractID].getService(kWindowMediatorIID);

var browserWindow = kWindowMediator.getMostRecentWindow("navigator:browser");

var browser = browserWindow.getBrowser();

var tab = browser.addTab("https://www.google.de/?gfe_rd=cr&ei=BwkjVKfAD8uH8QfckIGgCQ&gws_rd=ssl;);

 

This will work from anywhere in Firefox. Sidebar, popup and ordinary pages.

 

got from Larry William's Weblog

 

XS: IE and Mozilla also provide the _search value to open links in the search sidebar.

Share this post


Link to post
Share on other sites

you got to put quote tags around that, since you have got it from another site!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.