So, I have the following code for an extension that cycles through open tabs with a specific URL.
chrome.browserAction.onClicked.addListener(function(tab) {
console.log('Get URL');
chrome.tabs.query(
{currentWindow: true, url: 'http://ift.tt/UHDl5t'},
function(tabs) {
tabs.forEach(function(tab) {
console.log('Tab ID, URL: ', tab.id, ' ', tab.url);
if(tab.url !== '')
{
//tab.focus();
console.log('if !== \'\'');
chrome.browserAction.setBadgeText({text: "YES"});
chrome.browserAction.setBadgeBackgroundColor({color: "GREEN"})
var updateProperties = {"active": true};
chrome.tabs.update(tab.id, updateProperties, function(tab){ });
}
else
{
chrome.windows.create({ url: "https://www.google.com", type: "popup" });
chrome.browserAction.setBadgeText({text: "NO"});
chrome.browserAction.setBadgeBackgroundColor({color: "RED"})
}
});
});
If the array has items, then the if condition is true, and the instructons for if are executed. If the array has no items, then the if condition is false and nothing is executed. My understanding is, that the set of instructions in else should be executed.
Aucun commentaire:
Enregistrer un commentaire