Chrome Extension: onclick extension icon, open popup.html in new tab

后端 未结 3 1446
夕颜
夕颜 2020-12-09 03:50

I have created a chrome extension and managed to open the popup.html file using window.open. however I want to open it in a new tab, I\'ve tried lo

3条回答
  •  孤城傲影
    2020-12-09 04:37

    Use chrome.tabs.create(Object properties, function callback) as described on http://code.google.com/chrome/extensions/tabs.html

    The object properties could contain fields for windowId, index, url and selected. The optional callback function receives a Tab object of the newly created tab.

    So the simplest example to create a new tab in the current window and get it selected would look like this:

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

    Not sure why you would like to show the popup.html in a new tab, but I find it very useful while developing/debugging my extension ... it is quite a pain that on the extension page there is "usually" only a link to the background page.

    Would love to know how to open it in a new window and maybe in a kiosk mode ;-)

提交回复
热议问题