Retrieving which tabs are open in Chrome?(检索 Chrome 中打开了哪些标签页?)
问题描述
有没有办法在 Chrome 中检索所有打开的选项卡并将它们排序到一个数组中?因此,如果 Gmail 和 YouTube 已打开,则数组中将有两个条目,标题为gmail.com"和youtube.com".
Is there a way to retrieve all the tabs open and sort them in to an array in Chrome? So if Gmail and YouTube were open, there would be two entries in the array entitled "gmail.com" and "youtube.com".
推荐答案
是的,你可以这样做:
注意:这需要在清单文件中指定标签"权限.
Note: this requires permission "tabs" to be specified in your manifest file.
chrome.windows.getAll({populate:true}, getAllOpenWindows);
function getAllOpenWindows(winData) {
var tabs = [];
for (var i in winData) {
if (winData[i].focused === true) {
var winTabs = winData[i].tabs;
var totTabs = winTabs.length;
for (var j=0; j<totTabs;j++) {
tabs.push(winTabs[j].url);
}
}
}
console.log(tabs);
}
在此示例中,我只是按照您在数组中的要求添加选项卡 url,但每个选项卡"对象都包含更多信息.Url 将是完整的 URL,您可以应用一些正则表达式从 URL 中提取域名.
In this example I am just adding tab url as you asked in an array but each "tab" object contains a lot more information. Url will be the full URL you can apply some regular expression to extract the domain names from the URL.
这篇关于检索 Chrome 中打开了哪些标签页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检索 Chrome 中打开了哪些标签页?
基础教程推荐
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
