Is there a way track the focus on tab with Javascript?
问题 We need to track the EFFECTIVE time on site of our users Most users, when they're done, leave the tab open and move to another tab Time on site it's extremely inaccurate Is there a Javascript Event to track the "loss of focus" of the current tab ? 回答1: This should work both on tab switch and on browser window losing focus: function onBlur() { document.body.className = 'blurred'; }; function onFocus(){ document.body.className = 'focused'; }; if (/*@cc_on!@*/false) { // check for Internet