6

Since the permission "tabs" and chrome.tabs API are not available in Chrome Apps, how can I open a tab in the browser with specified URL?

Xan
  • 74,770
  • 16
  • 179
  • 206
Stephan
  • 594
  • 7
  • 17

3 Answers3

4

Try dynamically creating a link and call its click method.

function openTab(url) { 
    var a = document.createElement('a'); 
    a.href = url; 
    a.target='_blank'; 
    a.click(); 
}

You could then call that function like this:

openTab('http://google.com');

Update

The previous example opens the link in the default browser (which could be something other than Chrome)

If you want to force the link to open in chrome, use window.open

window.open('http://google.com');
lostsource
  • 21,070
  • 8
  • 66
  • 88
  • What if my default browser is not Chrome? – Samik Apr 19 '14 at 08:21
  • @SamikSaha in that case you could use `window.open` .. eg. `window.open('http://google.com')` , that should always open Chrome when called from within a Chrome App (answer updated) – lostsource Apr 19 '14 at 09:45
  • Unfortunately `window.open` also opens the link in default browser – Samik Apr 20 '14 at 03:55
3

In your manifest file, add "browser" to your permissions:

"permissions": ["browser", ...],

Then in your js file, call function chrome.browser.openTab to open your link on Chrome.

 chrome.browser.openTab({
   url: "your_url"
 });
Xan
  • 74,770
  • 16
  • 179
  • 206
user3444693
  • 464
  • 4
  • 7
0

There is now chrome.browser.openTab which should do what you want

kzahel
  • 2,765
  • 1
  • 22
  • 31