How to detect if a window is out of focus?

C

Charles

Is there a way to detect if a window is out of focus?

Here's what I need it for: I have a web-based chat application that one
of the 2 people chatting may have the chat window open or minimized.

When the chat window is open, probably it's because the person is
reading the other person's messages or because he/she is typing a
message. When the chat window is minimized it's probably because none
of the guys have chatted over the last minutes, and probably because no
one is typing.

Now, if some one sends a message to the other guy, I want the
recipient's minimized window to blink in his task bar so that he knows
he's got a new message. To do this, I would remotely ask to give focus
to his window. But if by chance the recipient is typing a message, his
window isn't out of focus, and if I ask to give focus to his window,
his textarea where he's writing will lose focus, and he won't be able
to type anymore until he manually gives focus again to the textarea
where he was typing.

Do you get the picture? How do I know if a window is out of focus?
Thanks,
 
E

Erwin Moller

Charles said:
Is there a way to detect if a window is out of focus?

Here's what I need it for: I have a web-based chat application that one
of the 2 people chatting may have the chat window open or minimized.

When the chat window is open, probably it's because the person is
reading the other person's messages or because he/she is typing a
message. When the chat window is minimized it's probably because none
of the guys have chatted over the last minutes, and probably because no
one is typing.

Now, if some one sends a message to the other guy, I want the
recipient's minimized window to blink in his task bar so that he knows
he's got a new message. To do this, I would remotely ask to give focus
to his window. But if by chance the recipient is typing a message, his
window isn't out of focus, and if I ask to give focus to his window,
his textarea where he's writing will lose focus, and he won't be able
to type anymore until he manually gives focus again to the textarea
where he was typing.

Do you get the picture? How do I know if a window is out of focus?
Thanks,

Why not just keep track of it?
Like this:

<html>
<head>

<script type="text/javascript">
self.setTimeout("showFocus();",100);

var Blurred = false;

function showFocus(){

// get all windowproperties.
var theDiv = document.getElementById("cont");

var theContent = "Blurred=";
if (Blurred){
theContent += "TRUE<br>";
} else {
theContent += "FALSE<br>";
}

theDiv.innerHTML = theContent;

self.setTimeout("showFocus();",1000);
}


</script>


</head>
<body onBlur="Blurred=true;" onFocus="Blurred=false;">
<div id="cont">
cont here
</div
</body>
</html>


If you run that simple page you will see the Blurred= will change with the
focus/blur.

Regards,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top