javascript Chrome 扩展程序:打开没有弹出窗口的选项卡

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5642116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 17:52:28  来源:igfitidea点击:

Chrome Extension: Open tab without popup

javascriptgoogle-chromegoogle-chrome-extensionchromium

提问by usertest

I've used the following code in my popup.html file:

我在 popup.html 文件中使用了以下代码:

<script type="text/javascript" charset="utf-8">
    chrome.tabs.create({'url': chrome.extension.getURL('page.html')}, function(tab) {
    });
</script>

When I click the extension icon a new page does open, but so does an empty browser popup near the button. How do I open the tab without the empty popup appearing?

当我单击扩展程序图标时,会打开一个新页面,但按钮附近的空浏览器弹出窗口也会打开。如何在不出现空弹出窗口的情况下打开选项卡?

Thanks.

谢谢。

回答by serg

Popup is optional. Just remove default_popupproperty from your manifest and then you can listen to icon click events in a background pageor event page:

弹出窗口是可选的。只需default_popup从清单中删除属性,然后您就可以在后台页面事件页面中收听图标点击事件:

chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.create({
        'url': chrome.extension.getURL('page.html')
    }, function(tab) {

    });
});