Reputation: 1512
I have written an extension, which changing his icon on websites, who matches the if clause. Take a look:
chrome.tabs.onActivated.addListener(
function (activeInfo) {
chrome.tabs.get(activeInfo.tabId, function(tab){
hosterRegExp(tab.url); //Function to change Icon
});
}
);
chrome.tabs.onUpdated.addListener(
function checkHosts(tabId, changeInfo, tab) {
hosterRegExp(tab.url); //Function to change Icon
}
);
Every time the active tab is changed or a tab is getting reloaded the function hosterRegExp is called with the current URL. This works fine.
Now, that's not working with two windows. If I change between two windows, it doesn't call the hosterRegExp(); that's because the active tab is not reloaded nor is it changing the active tab.
Also I couldn't find another EventHandler which would help me. So I have to check also the current windowID? I don't know - please help me.
Thank you.
Upvotes: 2
Views: 439
Reputation: 1512
Like RobW told me, I'm using the
chrome.windows.onFocusChanged
API now.
Well, in my case it will look like this:
chrome.windows.onFocusChanged.addListener(function()
{
chrome.tabs.query({currentWindow: true, active: true}, function(tab)
{
hosterRegExp(tab[0].url);
});
});
I used the query method to get the tab after the changed focus. Though it isn't possible that 2 tabs are active in one window, the array has everytime only one element.
That's not beautiful, if someone has a better and cleaner code, tell me!
Upvotes: 3