$(window).focus(function() { window.is_active = true; }); $(window).blur(function() { window.is_active = false; });