Stephan
Stephan

Reputation: 594

Open a tab in browser from a Chrome App

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?

Upvotes: 6

Views: 4074

Answers (3)

user3444693
user3444693

Reputation: 454

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"
 });

Upvotes: 3

kzahel
kzahel

Reputation: 2785

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

Upvotes: 0

lostsource
lostsource

Reputation: 21860

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');

Upvotes: 4

Related Questions