Open chrome extension in a new tab

谁都会走 提交于 2019-12-31 22:41:09

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/9576615/open-chrome-extension-in-a-new-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!