跨浏览器:检测窗口上的模糊事件 [英] Cross-browser: detect blur event on window

查看:107
本文介绍了跨浏览器:检测窗口上的模糊事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚读过,我认为处理这个问题的所有线程,我都无法找到解决问题的真正方法。
我需要检测浏览器窗口何时失去焦点,即模糊事件。
我已经尝试了stackoverflow上的所有脚本,但似乎没有一个合适的跨浏览器方法。

I just read, I think all the thread that deals with this subject, and I can't find a real solution to my problem. I need to detect when the browser window loses its focus, i.e. a blur event. I've tried all the scripts on stackoverflow, but there doesn't seem to be a proper cross-browser approach.

Firefox是这里有问题的浏览器。

Firefox is the problematic browser here.

使用jQuery的常用方法是:

A common approach using jQuery is:

window.onblur = function() { 
   console.log('blur'); 
}
//Or the jQuery equivalent:
jQuery(window).blur(function(){
    console.log('blur');
});

这适用于Chrome,IE和Opera,但Firefox不会检测到该事件。

This works in Chrome, IE and Opera, but Firefox doesn't detect the event.

是否有适当的跨浏览器方式来检测窗口模糊事件?
或者,换句话说,有没有办法用Firefox浏览器检测窗口模糊事件?

Is there a proper cross-browser way to detect a window blur event? Or, asked differently, is there a way to detect a window blur event with the Firefox browser?

相关问题和研究:


  • 参见 Firefox 3窗口焦点和模糊

  • 根据以下github文章,jQuery已经停止支持Firefox模糊测试:

    • See Firefox 3 window focus and blur
    • According to the following github articles, jQuery has discontinued support for Firefox blur testing:
      • https://github.com/jquery/jquery/pull/1423
      • http://bugs.jquery.com/ticket/13363

      推荐答案

      我试过了两个:

      document.addEventListener('blur', function(){console.log('blur')});
      

      window.addEventListener('blur', function(){console.log('blur')});
      

      他们都在我的FF(33.1)版本中工作。

      and they both worked in my version of FF (33.1).

      以下是jsfiddle: http://jsfiddle.net/hzdd06eh/

      Here's the jsfiddle: http://jsfiddle.net/hzdd06eh/

      在运行窗口内单击,然后在其外部单击以触发效果。

      Click inside the "run" window and then click outside it to trigger the effect.

      这篇关于跨浏览器:检测窗口上的模糊事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆