views:

92

answers:

2

How do I open a link in a new tab in the extension HTML.

E.g.

clicks on icon

sees Google chrome window which has the window.html

inside there are two links, one link to open a link in a new tab, other in the original tab.

I used window.location, doesn't work like that.

+3  A: 

I don't know why this question has two upvotes, but anyway you can try using the target attribute for anchor elements.

<a target="_blank" src="http://myFancyUrl"&gt;This is a link to a new tab</a>

However, it won't open in a new tab unless the user has the navigator configured that way (usually does).

Matias
It's _blank, not blank
M28
Thanks. Answer edited to correct that typo.
Matias
+3  A: 

If the page is indeed in a google chrome extension, you can force the browser to open the page in a new tab using javascript (which you know is enabled sine you are a google chrome extension).

chrome.tabs.create({url:"http://somewhere", selected:true});

Your extension will need the tabs permission.

See: http://code.google.com/chrome/extensions/tabs.html

Pim Jager
Nice, I should give it a try
Matias