I want to detect if my browser window has a focus on it (is selected). I use the following code to do so:
$(window).focus(function() {
window.focusFlag = true;
}).blur(function() {
window.focusFlag = false;
});
Source: Using JQuery to bind "focus" and "blur" functions for "window", doesn't work in IE
It works on mozilla firefox 43.0.4, but it doesn't work on IE 11.
I also tried focus/blur method which does not involve JQuery.
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;
}
It also works on mozilla firefox 43.0.4, but it doesn't work on IE 11.
Srource: http://www.thefutureoftheweb.com/blog/detect-browser-window-focus
What can I do about IE 11?