我创建了一个chrome扩展,并设法使用window.open
打开popup.html
文件。但是我想在一个新的标签页中打开它,我已经尝试了很多不同的方法,包括:
<script type="text/javascript" language="JavaScript">
chrome.tabs.create('url': 'popup.html');
我只是把代码放在了错误的地方,还是完全错误的代码?
我创建了一个chrome扩展,并设法使用window.open
打开popup.html
文件。但是我想在一个新的标签页中打开它,我已经尝试了很多不同的方法,包括:
<script type="text/javascript" language="JavaScript">
chrome.tabs.create('url': 'popup.html');
我只是把代码放在了错误的地方,还是完全错误的代码?
5条答案
按热度按时间carvr3hs1#
为什么要在新标签页中打开popup.html?您应该为此创建一个不同的页面。无论如何,如果你想打开popup.html,在一个新的选项卡中,你需要传入扩展名url。
http://code.google.com/chrome/extensions/extension.html#method-getURL
bvjveswy2#
现在你可以使用Event Pages在新标签页中打开popup.html,当扩展图标被点击时,不需要创建一个default_popup页面。
清单:
js:
ovfsdjhp3#
按照http://code.google.com/chrome/extensions/tabs.html中的说明使用chrome. tables.create(对象属性,函数回调)
对象属性可以包含windowId、index、url和selected字段。可选的回调函数接收新创建的选项卡的Tab对象。
因此,在当前窗口中创建一个新选项卡并将其选中的最简单示例如下所示:
不知道为什么你想在一个新的选项卡中显示popup.html,但我发现它在开发/调试我的扩展时非常有用。在扩展页面上“通常”只有一个到背景页面的链接,这是相当痛苦的。
会很想知道如何在一个新窗口中打开它,也许在一个信息亭模式;- )
cig3rfwq4#
一个完整的工作示例:
Manifest.json
background.js
popup.html
jucafojl5#
Manifest v3,2023
大多数答案可能不会与manifest v3一起工作;很多API都随着更新而改变了。这是@BaijiFeiLong的答案的更新版本,将在v3中工作:
manifest.json
background.js
popup.html