Chrome扩展程序 - 标签数量

时间:2013-02-11 07:25:57

标签: google-chrome google-chrome-extension

如何获取打开的标签数量和浏览器中当前标签的编号?

3 个答案:

答案 0 :(得分:2)

使用chrome.tabs.getAllInWindow().length然后

chrome.tabs.getCurrent(function(Tab t) {
  // current tab index
  alert(t.index);
}) 

<强>更新

自Chrome 33以来,

getAllInWindow已弃用。您应query{windowId: chrome.windows.WINDOW_ID_CURRENT}{currentWindow: true}一起使用。

答案 1 :(得分:0)

自Chrome 16以来,请使用https://developer.chrome.com/extensions/tabs#method-query

示例:

chrome.tabs.query({}, function(foundTabs) {
        var tabsCount = foundTabs.length;
        console.info("tabsCount = " + tabsCount);
    });

答案 2 :(得分:-1)

尝试使用此扩展程序:Tabs Counter

相关问题