Skip to content

Instantly share code, notes, and snippets.

@titanew
Created October 24, 2014 09:30
Show Gist options
  • Save titanew/222358c4becdf1d34790 to your computer and use it in GitHub Desktop.
Save titanew/222358c4becdf1d34790 to your computer and use it in GitHub Desktop.
Detecting focus of a browser window
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