Open chrome extension in a new tab

2020-05-27 11:34发布

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?

2条回答
神经病院院长
2楼-- · 2020-05-27 11:40

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.

查看更多
Anthone
3楼-- · 2020-05-27 12:00

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.

查看更多
登录 后发表回答