views:

523

answers:

3

I have a friefox sidebar extension. If its opened by clicking on the toolbar icon I load it with a webpage ( that I have authored ). Now, if the user clicks on the link on the webpage ( thats loaded into the sidebar ) I want the linked webpage to open up in a new tab of the main window. I tried with this in my webpage markup:

<a target="_content" href="http://www.google.com"&gt;Google&lt;/a&gt;

But the link opens up in the tab that has focus and not in a new tab.

Please help.

Thanks.

A: 
<a href="http://www.google.com" target="new">Google</a>

This is more dependent on the browser that is being used. Firefox and Opera, and I'm sure the newest IE, display "new windows" as a new tab unless otherwise specified by user preference.

SD
+2  A: 

If you use target="_blank" instead, FF (version 3) should open a new tab for it. Haven't tried it from a sidebar, but it's worth giving a shot.

tehvan
_blank and new/_new are interchangeable anchor attributes. :)
SD
Thanks SD, i didn't know :)
tehvan
+1  A: 

Actually, there is no way to load a webpage ( whose link was in another webpage loaded into the sidebar extension ) onto a new tab in the browser. The only way is to use javascript. That has to execute under privileged conditions ( meaning as part of an extension ) like below:

gBrowser.addTab("http://www.google.com/");

EDIT:

The above technique of adding a browser tab did not work in this case. According to this article code running in the sidebar does not have access to the main window. So first up I got access to the browser window before using gBrowser. Here is the code taken from the website that I used and works properly:

var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);

After I got access to the browser window I accessed gBrowser through the getBrowser function like below:

mainWindow.getBrowser().addTab("http://www.google.com/");

The opens up a new tab in the main window browser.

ardsrk