473,805 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3677
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 windowpropertie s.
var theDiv = document.getEle mentById("cont" );

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

theDiv.innerHTM L = theContent;

self.setTimeout ("showFocus();" ,1000);
}
</script>
</head>
<body onBlur="Blurred =true;" onFocus="Blurre d=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
3472
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 a flexgrid. Briefly, the technique is to overlay the cell to be edited with "floating" textbox; data is edited in the floating textbox and moved to the cell when the floating textbox loses focus. The technique works well except for when the...
2
4228
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 windows to the front (top) in Netscape, IE and Opera. However, this command does nothing when you access the web page through AOL, even though they say this is IE. Once a window is behind (blurred), I have been unable to bring it back to the front...
9
48971
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 call to window.open As opposed to closing and re-opening new windows, I would prefer that when the user is finished reading the complete record, they can click a link whereby the main window is sent in to focus.
1
16606
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 that the application being brought foreward can take control. It has been my observation that when I set the window.onblur function, the window will gain focus and then immediately lose focus (blur) to the first field, button, or whatever that is...
22
10367
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 scann all items/elements on the page for a z-index? Thanks, Wouter
23
6533
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 know if Window.Open has been redefined? BACKGROUND:
4
68053
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 these forms that may make one succeed and another fail? In particular, this.window.focus() fails in Opera 9.10 with an "object not found", and windows.focus() succeeds in Opera 9.10, Firefox 2.02, and IE 7.
3
9488
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 property in my form: public new Control ActiveControl { get{ return base.ActiveControl; } set{ base.ActiveControl = value; } }
3
1671
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 computers which cannot, but either way they are all on netscape), the current onclick command looks like this: <A onclick="wopen('page url', 'popup', 670, 395); return false;" href="page url" target=popup> which activates this script: <SCRIPT>...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10370
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5545
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.