I am trying to detect in my background page if the selected tab of chrome changes. For example if the user is on www.google.com in one tab and he changes to www.yahoo.com in another tab what is the best way of detecting
Asked
Active
Viewed 131 times
1
-
1Check out http://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active but that is more for a webpage – Dean Taylor Dec 30 '13 at 02:03
-
1For a chrome extension check out `onActivated `https://developer.chrome.com/extensions/tabs.html#event-onActivated – Dean Taylor Dec 30 '13 at 02:06
-
1If this is for a Google Chrome Extension check this question out: http://stackoverflow.com/questions/12558528/chrome-tab-onactivated – Dean Taylor Dec 30 '13 at 02:21
-
Hi Dean. That seems to be exactly what I am looking for. For some strange reason I did not notice it when browsing the api. – KennyBartMan Dec 30 '13 at 02:39
2 Answers
1
I will answer my own question here. Within the chrome API the chrome.tabs.onActivated event is the exact event that I want to use. Thank you Jeff for pointing this out.

KennyBartMan
- 940
- 9
- 21
0
The blur
event is fired on the window, but not only for tab changes.
It is fired when the window loses its focus (alt-tab to another app, click on the desktop etc)..
So something like
window.addEventListener('blur', function(e){
// just lost focus
}, false);

Gabriele Petrioli
- 191,379
- 34
- 261
- 317