Chrome如何获取当前标签的ID? [英] Chrome how to get the current tab's id?
问题描述
chrome.tabs.getCurrent(function(tab){
alert(tab.id);
});
是选项卡
一个对象?为什么它没有 id
属性?
如何获得 id
当前标签?
chrome.tabs.getCurrent(function (tab){console.log(JSON.stringify(tab,null,2));})
给我下一个
{
active:true,
audible:false,
favIconUrl:chrome-extension://eggkanocgddhmamlbiijnphhppkpkmkl/img/favicon.png ,
height:853,
highlight:true,
id:5280,
incognito:false,
index:0 ,
mutedInfo:{
muted:false
},
pinned:false,
selected:true,
status:complete,
title:Tabs Outliner,
url:chrome-extension://eggkanocgddhmamlbiijnphhppkpkmkl/activesessionview.html?type = main& focusNodeId = 5220& altFocusNodeId = 5046& scrollToViewWinId = 5046,
width:400,
windowId:5279
}
列表您可以在 https://developer.chrome.com/extensions/tabs#中找到所有道具类型 - 标签 --- 标记为可选的标识
标签的ID。标签ID在浏览器会话中是唯一的。在某些情况下,可能不会为某个选项卡分配一个ID,例如,在使用会话API查询外部选项卡时(在这种情况下可能存在会话ID)。 >标签ID也可以设置为chrome.tabs.TAB_ID_NONE,适用于应用程序和开发工具>窗口。
如果您尝试运行代码从控制台
标签ID也可以设置为chrome.tabs.TAB_ID_NONE,适用于应用程序和开发工具> windows。
chrome.tabs.getCurrent(function(tab){
alert(tab.id);
});
Is tab
an object? Why doesn't it have an id
property?
How can I get the id
of the current tab?
chrome.tabs.getCurrent(function(tab){ console.log(JSON.stringify(tab,null, 2)); })
gives me next
{
"active": true,
"audible": false,
"favIconUrl": "chrome-extension://eggkanocgddhmamlbiijnphhppkpkmkl/img/favicon.png",
"height": 853,
"highlighted": true,
"id": 5280,
"incognito": false,
"index": 0,
"mutedInfo": {
"muted": false
},
"pinned": false,
"selected": true,
"status": "complete",
"title": "Tabs Outliner",
"url": "chrome-extension://eggkanocgddhmamlbiijnphhppkpkmkl/activesessionview.html?type=main&focusNodeId=5220&altFocusNodeId=5046&scrollToViewWinId=5046",
"width": 400,
"windowId": 5279
}
List of all props you can find at https://developer.chrome.com/extensions/tabs#type-Tab --- id marked as optional
The ID of the tab. Tab IDs are unique within a browser session. Under some >circumstances a Tab may not be assigned an ID, for example when querying >foreign tabs using the sessions API, in which case a session ID may be present. >Tab ID can also be set to chrome.tabs.TAB_ID_NONE for apps and devtools >windows.
That's important if you try run code from console
Tab ID can also be set to chrome.tabs.TAB_ID_NONE for apps and devtools >windows.
这篇关于Chrome如何获取当前标签的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!