$(window).focus(function() { console.log('user is watching this page'); }); $(window).blur(function() { console.log('user is not watching this page'); });