I need to know if the user is viewing the tab or not in Google Chrome. I tried using event blur and focus tied to the window, but only the blur seems to work correctly.
window.addEventListener('focus', function() { document.title = 'focused'; }); window.addEventListener('blur', function() { document.title = 'not focused'; });
A focus event works strangely, only occasionally. If I switch to another tab and back, the focus event will not be activated. But if I click on the address bar and then return to the page, this will happen. Or, if I switch to another program and then return to Chrome, it activates if the tab is currently focused.
javascript google-chrome focus
fent Apr 27 '10 at 11:20 2010-04-27 11:20
source share