473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How to detect if a window is out of focus?

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,

Jul 19 '06 #1
2 3638
Charles wrote:
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
Jul 20 '06 #2
Thank you Erwin, this did the trick :)

Jul 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: selowan | last post by:
Hi, In VB6 Pro SP5, I have a form that contains an MSFlexGrid and a few other textboxes and comboboxes. I am using the technique from MSDN article Q241355, which describes how to tab and edit in...
2
by: Fred Snider | last post by:
Help! Opening a new window using the window.open( ) command works great for opening new windows and having them on top and having the focus. The window.focus command brings any existing...
9
by: Randell D. | last post by:
Folks, I'm working on a contact name/address database whereby a slimed down list is shown in the main window. When a record is selected, the complete record is displayed in a new window via a...
1
by: Barry Svee | last post by:
I'm struggling with the JavaScript blur event. I have an activex control that I need to interact with when a window loses focus, namely to instruct it to give up control of a barcode scanner so...
22
by: DJ WIce | last post by:
Hi, I'm looking for a script to get the hi-est z-index on a page. I want my javascript menu to be always on top of the page (moves along on top when you scroll down). Does anyone know how to...
23
by: David McCulloch | last post by:
QUESTION-1: How can I detect if Norton Internet Security is blocking pop-ups? QUESTION-2a: How could I know if a particular JavaScript function has been declared? QUESTION-2b: How could I...
4
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between...
3
by: nano2k | last post by:
Each form has its ActiveControl property, but no ActiveControlChanged event to signal that the active control has changed (like ParentChanged event). I tried to trick the form by declaring this...
3
by: topherknowles | last post by:
Hello, I have a number of links opening in a fixed window that certain users cannot access because they are on netscape 4.6 (I think this can handle the links and it is actually their ancient...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.