JQuery - window focus, event blur does not start - works in Firefox and Chrome

In a nutshell; I wrote a simplified chat application for me and me. When there is no focus in the window on which the application is running (minimized or behind other windows) and a message appears, I want to change the title bar of the windows to serve as an alert. Just like the Google chat app in GMail.

Everything works flawlessly in Firefox and Chrome, but not in IE7 (8 not tested).

This is the code that I use to determine if focus has focus. Could it be written differently to work in IE? In addition, I am open to any other approaches to achieve the same. Thank you very much in advance.

$(window).bind("blur", function() { hasfocus = false; }); $(window).bind("focus", function() { hasfocus = true; }); 
+4
source share
3 answers

I do not think google chat uses a window to check focus. It uses the user text field that communicates with you. As soon as the text field receives focus, "Says ..." stops the loop.

You might want to check the mouse movement to see if the window has focus. Other than that, I'm still trying to figure out how to check the focus window while trying to save a live page.

+2
source

This jquery bit will work in IE and all good browsers (chrome, ff, etc.). The key is a focusin \ focusout document for supporting IE.

 $(function(){ $(window).bind('blur', function(){ console.debug('window blur'); }); $(window).bind('focus', function(){ console.debug('window focus'); }); // IE EVENTS $(document).bind('focusout', function(){ alert('document focusout'); }); $(document).bind('focusin', function(){ alert('document focusin'); }); }); 
+2
source

What happens if you try to link a document item?

0
source