Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open chrome extension in a new tab

I have implemented a chrome extension. Was wondering if the popup.html can be opened in a new tab? Every single click on the page, and the popup disappears :( .. Was wondering if I can stick it to the page or is there a way to open the extension in a new page?

like image 459
sharath Avatar asked Mar 06 '12 01:03

sharath


2 Answers

Yes, a popup page is just a normal extension page, you can do the following to open a new popup tab from the background page. I use that every time when the user first installs the extension, I open the about page, you can do the same for the popup page.

chrome.tabs.create({url: 'popup.html'}) 

For one of my extensions, My Hangouts, I have a small "open as tab" button within the popup, I bind the click event for that link to execute this:

chrome.tabs.create({url: chrome.extension.getURL('popup.html#window')});

The reason why I passed the hash is because I wanted to add more content when the user opens it in a popup because there is more real estate to play with.

Within the popup, I use normal JavaScript to differentiate whether I opened the tab in the new tab page or in a normal page like the following:

if (window.location.hash == '#window') {
  this.displayAsTab = true;
}

You can do tricks like this to make your extensions user experience better.

like image 98
Mohamed Mansour Avatar answered Sep 28 '22 08:09

Mohamed Mansour


here is the same issue: Chrome Extension: onclick extension icon, open popup.html in new tab

use:

chrome.tabs.create({'url': chrome.extension.getURL('popup.html')}, function(tab) {
    // Tab opened.
});

property "pinned" to stick the tab.

like image 27
Vinta Avatar answered Sep 28 '22 08:09

Vinta