Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome Chrome扩展以循环关闭未选择的选项卡_Google Chrome_Tabs - Fatal编程技术网

Google chrome Chrome扩展以循环关闭未选择的选项卡

Google chrome Chrome扩展以循环关闭未选择的选项卡,google-chrome,tabs,Google Chrome,Tabs,我为Safari做了这个扩展,它关闭当前页面上的非活动选项卡 (var tabss = safari.application.activeBrowserWindow.tabs; for (n=0; n<tabss.length; n++) { if(tabss[n] != safari.application.activeBrowserWindow.activeTab) tabss[n].cl

我为Safari做了这个扩展,它关闭当前页面上的非活动选项卡

 (var tabss = safari.application.activeBrowserWindow.tabs;

            for (n=0; n<tabss.length; n++) 
              {
          if(tabss[n] != safari.application.activeBrowserWindow.activeTab)

         tabss[n].close();
             }
    )
(var-tabss=safari.application.activeBrowserWindow.tabs;
对于(n=0;n这应该做到:

// when a browser action is clicked, the callback is called with the current tab
chrome.browserAction.onClicked.addListener(function(curtab)
{
     // get the current window
    chrome.windows.getCurrent(function(win)
    {
        // get an array of the tabs in the window
        chrome.tabs.getAllInWindow(win.id, function(tabs)
        {
            for (i in tabs) // loop over the tabs
            {
                 // if the tab is not the selected one
                if (tabs[i].id != curtab.id)
                {
                    // close it
                    chrome.tabs.remove(tabs[i].id)
                }
            }
        });
    });
});

哇。很快就把那些标签搞定了。谢谢。我昨晚花了几个小时来学习这些东西/想办法。哈哈。谢谢。
(
            for (n=0; n<tabCount; n++) 
              {
          if(chrome.tabs[n].id != tab.id)

         chrome.tabs[n].remove();
             }
)
// when a browser action is clicked, the callback is called with the current tab
chrome.browserAction.onClicked.addListener(function(curtab)
{
     // get the current window
    chrome.windows.getCurrent(function(win)
    {
        // get an array of the tabs in the window
        chrome.tabs.getAllInWindow(win.id, function(tabs)
        {
            for (i in tabs) // loop over the tabs
            {
                 // if the tab is not the selected one
                if (tabs[i].id != curtab.id)
                {
                    // close it
                    chrome.tabs.remove(tabs[i].id)
                }
            }
        });
    });
});