Reputation: 2672
This is how I refresh all chrome tabs in my chrome extension.
chrome.tabs.getAllInWindow(null, function(tabs) {
for(var i = 0; i < tabs.length; i++) {
chrome.tabs.update(tabs[i].id, {url: tabs[i].url});
}});
I don't want to refresh all tabs, I just want to refresh a single tab that has a word 'Inbox' in its title.
Can someone help adjusting my code?
Upvotes: 2
Views: 228
Reputation: 2231
You can check if the tab have Inbox is in the title.
chrome.tabs.getAllInWindow(null, function(tabs)
{
for(var i = 0; i < tabs.length; i++)
{
if(tabs[i].title.indexOf("Inbox") != -1)
chrome.tabs.update(tabs[i].id, {url: tabs[i].url});
}
});
And in case where you are sure you only have one tab with that title, you can break to save a (very) litle time of exection :
chrome.tabs.getAllInWindow(null, function(tabs)
{
for(var i = 0; i < tabs.length; i++)
{
if(tabs[i].title.indexOf("Inbox") != -1)
{
chrome.tabs.update(tabs[i].id, {url: tabs[i].url});
break;
}
}
});
Upvotes: 2