Created
January 19, 2011 21:39
-
-
Save shinypb/786923 to your computer and use it in GitHub Desktop.
Test whether your browser supports window focus/blur events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<script> | |
var timer = startTimer(); | |
function startTimer() { | |
return setInterval(function() { | |
console.log('tick'); | |
}, 1000); | |
} | |
window.onblur = function() { | |
if(timer) { | |
console.log('stopping'); | |
clearInterval(timer); | |
timer = null; | |
} | |
} | |
window.onfocus = function() { | |
if(!timer) { | |
console.log('starting'); | |
timer = startTimer(); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment