jQuery-窗口焦点,模糊事件未触发-在Firefox和Chrome中有效 [英] jQuery - window focus, blur events not triggering - works in Firefox and Chrome

查看:102
本文介绍了jQuery-窗口焦点,模糊事件未触发-在Firefox和Chrome中有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之;我为好友编写了一个简单的聊天应用程序,供我使用.当运行该应用程序的窗口没有焦点(最小化或在其他窗口后面)并且出现消息时,我想更改窗口标题栏以作为警报.就像Google的聊天应用程序在GMail中一样.

In a nutshell; I wrote a simplistic chat application for a buddy and me to use. When the window running the application does not have the focus (minimized or behind other windows) and a message comes in, I want to change the windows title bar to serve as an alert. Exactly like Google's chat application does in GMail.

一切都可以在Firefox和Chrome中完美运行,但在IE7中则无法运行(尚未测试8).

Everything works flawlessly in Firefox and Chrome but not in IE7 (haven't tested 8).

这是我用来确定窗口是否具有焦点的代码.可以用不同的方式编写此文字以便在IE中也可以使用吗?另外,我愿意接受其他任何方法来完成同一件事.预先非常感谢.

This is the code I am using to determine if the window has focus. Can this be written differently to also work in IE? Also, I'm open to any other approaches to accomplish the same thing. Many thanks in advance.

  $(window).bind("blur", function() {
    hasfocus = false;
  });

  $(window).bind("focus", function() {
    hasfocus = true;
  });

推荐答案

我不认为Google聊天使用该窗口来检查焦点.它使用与您聊天的用户的文本框.文本框获得焦点后,说..."立即停止循环.

I don't think google chat uses the window to check focus. It uses the textbox of the user chatting to you. As soon as the textbox receives focus " Says..." stops looping.

您可能要检查鼠标的移动,以查看窗口是否具有焦点.除此之外,我仍在尝试找出在使页面保持活动状态时如何检查窗口的焦点.

You might want to check for mouse movements to see if the window has focus. Other than that, I am still trying to figure out how to check the window for focus when trying to keep a page live.

这篇关于jQuery-窗口焦点,模糊事件未触发-在Firefox和Chrome中有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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