首页 > chrome.tabs.getCurrent(function callback)

chrome.tabs.getCurrent(function callback)

chrome.tabs.getCurrent(function(Tab tab){

alert(tab.id);

})
这个方法没有获得tab对象吗?怎么没有id属性?
请教下大大们怎么获取选中标签的id?


帮你翻了下文档:

文档的意思很明确。

提供一种方法在 background.htmlpopup.html 中获取 currentTab

function getCurrentTab(callback) {
    chrome.tabs.query({
        active: true,
        windowId: chrome.windows.WINDOW_ID_CURRENT
    }, function (tabs) {
        if (tabs && tabs[0]) {
            callback(tabs[0]);
        }
    });
}

chrome.windows.WINDOW_ID_CURRENT 是当前 window 的ID

【热门文章】
【热门文章】