Chrome 扩展:点击扩展图标,在新标签页中打开 popup.html [英] Chrome Extension: onclick extension icon, open popup.html in new tab
问题描述
我创建了一个 chrome 扩展并设法使用 window.open
打开 popup.html
文件.但是我想在新标签页中打开它,我尝试了很多不同的方法,包括:
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 lots of different ways including:
<script type="text/javascript" language="JavaScript">
chrome.tabs.create('url': 'popup.html');
我只是把代码放在错误的地方还是完全错误的代码?
Am I just placing the code in the wrong place or is it the wrong code altogether?
推荐答案
为什么要在新选项卡中打开 popup.html?您应该为此创建一个不同的页面.无论如何,如果你想在新标签页中打开 popup.html,你需要传入扩展 url.
why would you want to open the popup.html in a new tab? You should create a different page for that. Anyways, if you want to open up the popup.html, in a new tab, you would need to pass in the extension url.
http://code.google.com/chrome/extensions/extension.html#method-getURL
chrome.tabs.create({'url': chrome.extension.getURL('popup.html')}, function(tab) {
// Tab opened.
});
这篇关于Chrome 扩展:点击扩展图标,在新标签页中打开 popup.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!