open a link in a new tab in the same window
Asked Answered
C

2

6

Hi I am making a firefox extension which needs to open a link in anew tab in the same window of firefox. How should i do this? This opens in a new window (replacing the old window):

window.location = url;

This opens in the same tab

window.content.document.location = url

Any idea on how to open the url in a new tab?

Connivent answered 11/5, 2010 at 6:18 Comment(0)
C
3

This works guys! :))

var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator);

var mainWindow = wm.getMostRecentWindow("navigator:browser");

mainWindow.gBrowser.selectedTab = mainWindow.gBrowser.addTab("http://google.com");
Connivent answered 11/5, 2010 at 7:5 Comment(0)
P
3

Have you tried window.open(url)? I'm guessing opening specifically in a new tab (as opposed to a new window) is part of the browser behavior that can't be controlled via JavaScript.

Provincetown answered 11/5, 2010 at 6:21 Comment(2)
this opens a new window (keeping the current window intact) No, I think it shoule be doable using javascript coz we are able to open it in all other possible waysConnivent
hrmm okay maybe mozilla has some documentation on how to do that in firefox. sorry i cant be of more help.Provincetown
C
3

This works guys! :))

var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator);

var mainWindow = wm.getMostRecentWindow("navigator:browser");

mainWindow.gBrowser.selectedTab = mainWindow.gBrowser.addTab("http://google.com");
Connivent answered 11/5, 2010 at 7:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.