Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > window blur event in ie when focus isn't lost

Thread Tools

window blur event in ie when focus isn't lost

nutso fasst
Posts: n/a
Perhaps this will be useful to someone...

I have a page with a document.onkeypress handler that uses
window.onblur/onfocus events to stop/start an interval timer. In IE 5,
clicking on a DIV with CSS 'position: absolute' fires a window.onblur event.
Subsequently clicking outside the DIV won't fire the window.onfocus event.
If I switch to another window and then back to the window in question, the
onfocus event fires, but the onblur event fires immediately after.
Consequently, neither the interval timer nor the keypress handler will
restart without a page reload.

The fix for this is to add an onfocus handler to the DIV element:

<div onfocus="this.blur()">

The likelyhood of someone accidently clicking on the DIV may be low, but
folks do sometimes click a visible portion of a window to give it focus and
I don't want any of them getting frustrated.


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie asks how to focus on subject and blur background Digital Photography 13 08-08-2007 04:39 PM
emulating window.focus in Body onload() event and setting focus to a control on same page Jason ASP .Net 4 05-07-2007 05:54 PM
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
Blur tutorial extra part, How Much Blur? Wayne J. Cosshall Digital Photography 0 02-16-2007 02:10 AM
popup window blur event lazar Javascript 2 07-20-2005 11:35 AM