jQuery - window focus, blur events not triggering - works in Firefox and Chrome
Posted
by brian newman
on Stack Overflow
See other posts from Stack Overflow
or by brian newman
Published on 2009-08-10T15:49:48Z
Indexed on
2010/04/17
2:53 UTC
Read the original article
Hit count: 1555
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.
Everything works flawlessly in Firefox and Chrome but not in IE7 (haven't tested 8).
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;
});
© Stack Overflow or respective owner