如何创建标签而不关闭弹出

How to create tab without closing the popup

本文关键字:标签 何创建 创建      更新时间:2023-09-26

当我从弹出窗口创建选项卡时,弹出窗口将关闭,bc选择为真。新选项卡被选中:

chrome.tabs.create({'url': 'http://www.google.com', 'selected' : true });

selectedfalse时,弹出窗口仍然存在,但新选项卡没有聚焦:

chrome.tabs.create({'url': 'http://www.google.com', 'selected' : false });

如何结合这一点,有新的选项卡和弹出可见在同一时间?我玩了chrome.tabs.move,但我觉得我在错误的方式。

有点晚了,但以防其他人也需要这个。我找到了一个绕过API:如果你先将当前选项卡设置为固定,然后在其他窗口中创建/删除/选择其他选项卡,然后取消当前选项卡,当前选项卡将保持打开状态,因此弹出窗口不会关闭。

chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
    const currentTab = tabs[0];
    // pin the current tab:
    chrome.tabs.update(currentTab.id, {pinned: true}, function(t){
        // do what you need to do here:
        chrome.tabs.update(someTabId, {}, function(){
        // un-pin the current tab
        chrome.tabs.update(currentTab.id, {pinned: false});
    });    
});

当您选择另一个窗口时,绝对没有办法保持弹出窗口打开。

如果你想推迟选择窗口,你可以先创建它,当你准备好了,你可以用chrome.tabs.update.

chrome.tabs.create({url: 'http://www.google.com', selected: false}, function(tab) {
  chrome.tabs.update(tab.id, {selected: true});
});