Created
October 24, 2014 09:30
-
-
Save titanew/222358c4becdf1d34790 to your computer and use it in GitHub Desktop.
Detecting focus of a browser window
This file contains hidden or 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
function onBlur() { | |
document.body.className = 'blurred'; | |
}; | |
function onFocus(){ | |
document.body.className = 'focused'; | |
}; | |
if (/*@cc_on!@*/false) { // check for Internet Explorer | |
document.onfocusin = onFocus; | |
document.onfocusout = onBlur; | |
} else { | |
window.onfocus = onFocus; | |
window.onblur = onBlur; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment