Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open a link in a new tab in the same window

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?

like image 741
encryptor Avatar asked May 11 '10 06:05

encryptor


2 Answers

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.

like image 116
tau Avatar answered Oct 10 '22 09:10

tau


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");
like image 30
encryptor Avatar answered Oct 10 '22 09:10

encryptor