简体   繁体   English

Chrome扩展程序查找标签

[英]Chrome extension find tabs

I am creating a chrome extension which should open a new tab when clicked, which would take you to google. 我正在创建一个chrome扩展程序,单击该扩展程序时应打开一个新标签,该链接会将您带到Google。

Currently I have this 目前我有这个

chrome.tabs.create({
    "url": "http://google.co.uk",
    "index":0,
    "pinned":true
});

how can I search the tabs too see if that tab is open and if it is pinned.If it is opened and pinned the prgram should do nothing, if open but not pinned it should pin that tab, and if not opened or pinned it should open the tab and pin it. 我如何搜索选项卡也可以查看该选项卡是否已打开以及是否已固定。如果已打开并固定了该选项卡,则prgram不应执行任何操作;如果已打开但未固定,则应将其固定;如果未打开或固定,则应该打开标签并将其固定。

Can I use 我可以用吗

chrome.tabs.query()

or do I need something else? 还是我需要其他东西?

You can use: 您可以使用:

chrome.tabs.query("http://google.co.uk", function(tabs)
{
    // if no tab found, open a new one
    if (tabs.length == 0){
        chrome.tabs.create({
            "url": "http://google.co.uk",
            "index":0,
            "pinned":true
        });
    }
    // otherwise, pin it
    else{
        chrome.tabs.update(tabs[0].id, { pinned: true });
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM