473,662 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using onblur to detect loss of window focus

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 contained within the
window. I can observe a text field gaining and losing focus as I
switch between applications but its parent window will *never* receive
any blur events as I switch between applications, so long as the
cursor remains in the text field.

Is there any way with JavaScript to know when the user is switching
focus from the browser window to some other application without having
to code logic into every friggin field on the page?

Barry
Jul 20 '05 #1
1 16582
Barry Svee wrote:
I'm struggling with the JavaScript blur event.
There are no JavaScript events, JavaScript itself neither provides
events nor event handling. Events and event handlers are provided
by the DOM of the used host, e.g. a HTML user agent.
I have an activex control that I need to interact with when a window ^^^^^^^^^^^^^^^ loses focus, [...]
And the IE browser component (IE) does not support JavaScript.
It supports JScript, Microsoft's implementation of ECMAScript,
which is nevertheless on-topic here. (See the FAQ.)
It has been my observation that when I set the window.onblur function,
To *what*? That is important.
the window will gain focus and then immediately lose focus (blur) to
the first field, button, or whatever that is contained within the
window.
I fail to observe that in my IE 6.0 SP-1 on Win2k (SP-4). Instead, I
observe that if a browser window is focused and the focus comes from
another application window, "onfocus" fires. If the focus comes from
another IE window, sometimes "onfocus", "onblur" and "onfocus" fire
(in that order) and sometimes only "onfocus" (the former is alas not
reproducible). No matter if the focus is lost in favor of another
application window or another IE window, "onblur" fires once.

Test Code was

javascript:void (window.onblur= function() {
document.body.a ppendChild(docu ment.createText Node("; onblur")); });
void(window.onf ocus=function() {
document.body.a ppendChild(docu ment.createText Node("; onfocus")); })

applied to about:blank.
Is there any way with JavaScript to know when the user is switching
focus from the browser window to some other application
No, there is not, unless the IE-DOM provides a property that I do not
know of. Maybe you can find it in
http://msdn.microsoft.com/library/de...node_entry.asp
without having to code logic into every friggin field on the page?


You need an event listener (function) for the "focus" event and apply it
to every window of your application, i.e. every displayed document of
it. The challenge you have to face is that the browser windows know
each other only if they are opened through window.open(... ). You can
then use the "opener" property of a window to reference the window that
opened it. In that first window you could maintain a list of references
to window objects as elements of an array or properties of a
user-defined object and thus reference the window to be changed on an event.
PointedEars
Jul 20 '05 #2

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

Similar topics

3
11607
by: Maria Bitsku | last post by:
How do I deactivate a window using Javascript. For example if I have a window that opens up another window, how do I prevent the user from clicking (doing anything) in the original window until the new window has been closed. Any insight will help. Thank you very much in advanced.
9
4511
by: CW | last post by:
I wrote an HTML based chat application. The front end is built entirely on HTML + javascript. Essentially, I have a hidden frame that's refreshed frequently and any new messages are displayed in another frame using document.write. My problem is that since chat screen can be obscured by other applications/windows, I have no way of informing users that new messages have arrived other than popping the window to the top using window.focus....
2
3711
by: D. Alvarado | last post by:
Hi, I'm having some trouble with the "onBlur" event in the BODY tag. Ideally, what I want to happen is that when someone leaves window A, window A executes a command. I had put <body onBlur="savePage();"> I have a couple of problems. On IE 6 (win2000), whenever I put the cursor focus on a textfield within window A, the "savePage" function is invoked. And on Mozilla Filefox 0.9.1, the event never launches even when I leave the...
6
7298
by: rob | last post by:
Hi I'm trying to create a "roll-up" effect when a window loses focus and then "roll-down" when it regains focus. This statement works properly with every browser I can get my hands on EXCEPT WinIE6. WinIE6 says there's an error in the code, but the debugging info says the problem is on line 1 char 1, which are comments. <Body bgcolor='black' Text='#dbdbdb' onblur='window.resizeTo(150,150)'
4
7078
by: Peter Pagé | last post by:
Hi, I've got a window with a "<body onBlur="window.close()"> tag that keeps closing prematurely. It happens when the user clicks on text inside a table in the same window. Apparently IE decides that the <body> no longer has the focus if the <table> within the <body> has it. Firefox handles the page correctly as does MS 5. This may be one of those "security features" that came along with Windows XP SP2, but wherever it came from,...
5
7585
by: Dave Hammond | last post by:
Hi All, I have a web form which performs certain actions upon moving focus away from a field. However, if the user clicks the top corner 'X' icon to close the window, the onBlur event still fires. If, for example, the onBlur event was an alert() popup: when the user clicks the close window icon, the window closes and then the alert pops up. Clearly, if the user closed the window, there is no point to performing the onBlur event.
1
2203
by: paulsson | last post by:
Does anyone know why placing the cursor/focus in a textfield in IE would cause the window.onblur event handler to be called? This seems very odd since the window still has focus.... Is there a way to prevent window.onblur form being called when a textfield in the same window gets focus or to test if the currently focused element is a textfield in window.onblur? I am testing on IE 6 on WinXP. Thanks, Erik
10
2447
by: John Kotuby | last post by:
Hello all... I am working on an ASP.NET 2.0 application with VS2005 and VB. I have chosen to use popup windows in some cases because it makes the user experience better (according to all the users I have polled who will be using this app). In an attempt to keep the popup from disappearing behind the calling window, I am adding the onblur="FocusMe():" event to the Body tag of the popup. I really want onblur to react to any click outside...
14
2960
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main reason you would want to do this is for example to trigger something from an OnPaint event without resorting to boolean switches-- say if a user presses the "M" key while the program is Painting, the user gets the PaintHandler to do something else. ...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8857
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...
0
8764
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5654
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
4180
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...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.