chrome.tabs.getCurrent(function(Tab tab){
alert(tab.id);
})
这个方法没有获得tab对象吗?怎么没有id属性?
请教下大大们怎么获取选中标签的id?
帮你翻了下文档:
文档的意思很明确。
提供一种方法在 background.html
或 popup.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