如何获取打开的标签数量和浏览器中当前标签的编号?
答案 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。