1document.addEventListener('visibilitychange', function() {
2 if(document.hidden)
3 console.log('Page is hidden from user view');
4 else
5 console.log('Page is in user view');
6});
7
1var interval_id;
2$(window).focus(function() {
3 if (!interval_id)
4 interval_id = setInterval(hard_work, 1000);
5});
6
7$(window).blur(function() {
8 clearInterval(interval_id);
9 interval_id = 0;
10});