Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 751
Stephan Avatar asked Jun 22 '13 10:06

Stephan


People also ask

How do I open two tabs side by side in Chrome on my phone?

First, open Chrome and pull up at least two tabs. Long-press the Android overview button to open the split-screen app selector. Then, open the Chrome overflow menu in the top half of the screen and tap "Move to other window." This moves your current Chrome tab into the bottom half of the screen.

How do I pin a tab in Chrome app?

Arrange tabs To pin a tab to the left, right-click the tab and select Pin. Pinned tabs are smaller and only show the site's icon. To unpin a tab, right-click the tab and select Unpin. To move a tab to a different window, right-click on the tab and point to Move tab to another window.

How do I open tabs in browser?

The fastest method to open a new tab in all browsers is to press the shortcut key combination Ctrl + T (PC users) or Command + T (Mac users).


2 Answers

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');
like image 115
lostsource Avatar answered Oct 02 '22 18:10

lostsource


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"
 });
like image 21
user3444693 Avatar answered Oct 02 '22 17:10

user3444693