Availability: |
| ||||||
Property/method value type: | Function object | ||||||
JavaScript syntax: | - | myWindow.onblur | |||||
- | myWindow.onblur = aHandler | ||||||
- | onblur | ||||||
- | onblur = aHandler | ||||||
HTML syntax: | <BODY onBlur="aHandler"> <FRAMESET onBlur="aHandler"> | ||||||
Argument list: | aHandler | An event handler function object |
A blur event is caused by the user clicking on another window or frame or the window.blur() method being called. When this event is triggered, an onblur event handler will be invoked.
The onblur event handler is a function which is represented by an object that is referred to by this property. Because it is stored in a property, you can change the handler by storing a reference to a different function object in this property. At least, you can on MSIE.
You cannot redefine the value of the window.onblur property from inside the onblur function handler. This means you can't modify the onblur behavior while a blur event is in progress.
The handler is registered either by assigning a function to the onblur property or by defining it with an HTML tag attribute.
Do not use <BODY ONBLUR="window.focus()"> to make sure the window is always on top. This does not work as you expect. The problem is caused because the BODY receives a blur event when any element inside the page takes the focus away from it (for example, when you click on a link or form element). The page becomes unusable because every attempt to click elements in the page triggers a javascript call that draws the focus straight back to the BODY/window. So all you get is a window that permanently blocks all the other windows but does not allow any elements inside it to be used.
In Netscape Navigator, the property is not enumerable if the value is defined with an onBlur="..." HTML tag attribute. However, it is enumerable if the property is assigned within JavaScript without there being a defining tag attribute. There may be a general rule that script defined properties are always enumerable, while internally created properties may not be.
Displaying an alert(), confirm() or prompt() dialog takes focus away from a window. Don't forget that your blur handler will be called if this happens.
The Macintosh version 4.7 of Netscape Navigator does not appear to support blur events.
See also: | onBlur, Window.blur(), Window.focus(), Window.onfocus |
Prev | Home | Next |
Window.offscreenBuffering | Up | Window.ondragdrop |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |