Chrome扩展程序:遍历所有标签页? [英] Chrome-Extension: iterate through all tabs?

查看:364
本文介绍了Chrome扩展程序:遍历所有标签页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何遍历用户打开的所有标签,然后检查它们是否包含特定的HTML项目( id ='item'?


解决方案

您可以像这样:

  chrome.tabs.getAllInWindow(null,function(tabs){
for(var i = 0; i< tabs.length; i ++){
chrome.tabs.sendRequest(tabs [i] .id ,{action:xxx});
}
});

之后,为了照顾你的物品,如果你能这样做:

  document.getElementById('item')

不要忘记,你不能使用背景页面操纵HTML因此,第一个代码片段用于背景页面,第二个代码片段必须位于内容脚本上;) p>

How would I iterate through all tabs a user has open and then check if they have a particular HTML item with id = 'item'?

解决方案

You can make it like this :

chrome.tabs.getAllInWindow(null, function(tabs){
    for (var i = 0; i < tabs.length; i++) {
    chrome.tabs.sendRequest(tabs[i].id, { action: "xxx" });                         
    }
});

After that to look after your item, if you can make it like this :

document.getElementById('item')

Don't forget that you can't manipulate the HTML by using the "background page" So the first code snip is for the background page, and the second have to be on a content script ;)

这篇关于Chrome扩展程序:遍历所有标签页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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