检索哪些标签在Chrome中打开? [英] Retrieving which tabs are open in Chrome?

查看:104
本文介绍了检索哪些标签在Chrome中打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法检索所有打开的标签并将它们分类到Chrome中的数组中?因此,如果Gmail和YouTube已打开,则阵列中将会有两个名为gmail.com和youtube.com的条目。 解决方案

是的,您可以这样做:

注意:这需要在清单中指定许可标签文件。

  chrome.windows.getAll({populate:true},getAllOpenWindows); 

函数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 tabs.push(winTabs [j] .url);
}
}
}
console.log(tabs);



$ b $ p
$ b

在这个例子中,我只是在数组中添加标签url,但是每个标签对象包含更多信息。 Url将是完整的URL,您可以应用一些正则表达式从URL中提取域名。


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".

解决方案

Yes, here is how you can do this:

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);
}

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中打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆