我想检测我的浏览器窗口是否有焦点(被选中)。我使用以下代码来执行此操作:
$(window).focus(function() {
window.focusFlag = true;
}).blur(function() {
window.focusFlag = false;
});
来源: Using JQuery to bind "focus" and "blur" functions for "window", doesn't work in IE
它适用于 mozilla firefox 43.0.4,但不适用于 IE 11。
我还尝试了不涉及 JQuery 的 focus/blur 方法。
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;
}
它也适用于 mozilla firefox 43.0.4,但不适用于 IE 11。
来源: http://www.thefutureoftheweb.com/blog/detect-browser-window-focus
我能对 IE 11 做些什么?
最佳答案
标准定义为 focus
:
This event type is similar to focusin, but is dispatched after focus is shifted, and does not bubble. https://www.w3.org/TR/uievents/#events-focusevent
因此, focusin
将在 jQuery 中为 parent 工作。
<input type="text" />
$(window).focusin(function() {
alert("Focussed");
}).focusout(function() {
alert("Blur");
});
关于javascript - JQuery Focus/Blur 和非 Jquery Focus/blur 在 IE 11 (Internet explorer 11) 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34767828/