views:

2318

answers:

4

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;
  });
A: 

What happens if you attempt to bind to the document element?

James Wiseman
A: 

So if !hasfocus you set the title?

Not sure how you are setting the title, but I have found it to be weird with jquery... For consistency I just use:

document.title = "New Title"

happytime harry
A: 

Dude, I have the same idea and problem as you. But my script has not work on Firefox yet. I posted a question about this. Do you mind answering the question? Or can you show me the code?

hoangquan
I ended up using dpgimnic's suggestion.
brian newman
+2  A: 

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.

dpgimnic