| Availability: |
| ||||||
| Property/method value type: | Boolean primitive | ||||||
| JavaScript syntax: | - | myObject.onerror = aHandler | |||||
| HTML syntax: | <HTMLTag onError="..."> <IMG onError="..."> | ||||||
| Argument list: | aHandler | A reference to a function object to handle the event. | |||||
| Supported by objects: | IMG, LINK, OBJECT, SCRIPT, STYLE | ||||||
There is an onError event defined as part of the set of events supported by JavaScript. However, the onError event is actually only supported by Image objects when defined in HTML tag attributes. You can add an error handler to a window object with the onerror property.
The <IMG onError="..."> tag attribute allows an error during image loading to be handled gracefully.
Attaching an error handler to a window with the window.onerror property allows JavaScript errors to be intercepted.
Error events have a slightly different parameter passing API so although they are events, they are slightly different from the rest of the event model.
The API for the function that is associated with this event should take three parameters.
This event handler cannot be set in HTML using the tag attribute technique apart from when it applies to an <IMG> tag. However, it also applies to windows and frames although there is no tag attribute to connect it to. You can only associate it with a window or frame by using the script-driven property assignment.
Beware of the return values. Returning true from an error handler inhibits the browser form carrying out any further action. This is exactly opposite to the return value from a form element event handler, which requires that a false value be returned to inhibit any further action by the browser.
The range of objects you can register an onError handler with is platform and browser version dependent and you should experiment with your target client base if you plan to use this other than for debugging help.
| Prev | Home | Next |
| onDrop | Up | onErrorUpdate |
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. | ||