22

我创建了一个 chrome 扩展名并设法popup.html使用window.open. 但是我想在新标签中打开它,我尝试了很多不同的方法,包括:

<script type="text/javascript" language="JavaScript">
  chrome.tabs.create('url': 'popup.html');

我只是将代码放在错误的位置还是完全错误的代码?

4

3 回答 3

22

为什么要在新选项卡中打开 popup.html?您应该为此创建一个不同的页面。无论如何,如果您想在新选项卡中打开 popup.html,您需要传入扩展 url。

http://code.google.com/chrome/extensions/extension.html#method-getURL

chrome.tabs.create({'url': chrome.extension.getURL('popup.html')}, function(tab) {
  // Tab opened.
});
于 2010-03-09T23:40:18.333 回答
9

现在,您可以在单击扩展图标时使用事件页面在新选项卡中打开 popup.html,而无需创建 default_popup 页面。

显现:

"background": {
    "scripts": ["background.js"],
    "persistent": false
}

js:

chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.create({'url': chrome.extension.getURL('popup.html'), 'selected': true});
});
于 2015-06-15T05:29:24.923 回答
3

按照http://code.google.com/chrome/extensions/tabs.html中的说明使用 chrome.tabs.create(Object properties, function callback)

对象属性可以包含 windowId、index、url 和 selected 字段。可选回调函数接收新创建的选项卡的 Tab 对象。

因此,在当前窗口中创建新选项卡并将其选中的最简单示例如下所示:

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

不知道为什么要在新选项卡中显示 popup.html,但我发现它在开发/调试我的扩展程序时非常有用......扩展页面上“通常”只有一个链接是相当痛苦的到后台页面。

很想知道如何在新窗口中打开它,也许在信息亭模式下;-)

于 2010-03-25T16:27:16.483 回答