473,382 Members | 1,563 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,382 software developers and data experts.

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 16528
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.appendChild(document.createTextNode( "; onblur")); });
void(window.onfocus=function() {
document.body.appendChild(document.createTextNode( "; 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
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...
9
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...
2
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...
6
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...
4
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...
5
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...
1
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...
10
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...
14
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...
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...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.