asp.net.ph

onerror Event

DHTML Events


Fires when an error occurs loading the object.

Syntax


Inline HTML <element onerror = "handler" ... > All platforms
Event property object.onerror = handler ECMA-262 Language Specification
Named script <script FOR=object EVENT=onerror> Internet Explorer® only

Event Handler Parameters

The following parameters apply only when this event is bound to the window object. These parameters are required in VBScript.


Parameter Description
msg Optional. Displays an error message. For use with the window object only.
url Optional. Provides the URL of the object on which the error occurred. For use with the window object only.
line Optional. Gives the line number in the source of the scripting error. For use with the window object only.

Remarks


Bubbles No
Cancels Yes
To invoke Cause an error to occur.
  • Cause an error while the window is loading, such as an error in scripting or a security problem.
  • Cause an error while downloading an object, such as an image.
Default action
  • Displays the browser error message when a problem occurs while loading the window.
  • Executes any error handling routine the programmer has associated with the event.

An error event occurs when an image does not load properly or when an error occurs during script execution. This event is valid for OBJECT elements, BODY elements, and FRAMESET element.

Setting the returnValue property of the event object to true, or simply returning true in JScript, suppresses the default Internet Explorer® error message for the window.

Event Object Properties

While event handlers in the Document Object Model do not receive parameters directly, the handler can query the event object for data.

Event Object Properties


Example

The examples demonstrate how to handle the onerror event on the window object, using parameters, as opposed to other objects where no parameters apply.

The example below incorporates the three arguments that can be passed for this event to catch errors that occur while the window is loading.

Sample Code

The following example demonstrates how to handle an error that occurs while an object is being downloaded.

<body>
<img src="whatever.gif" onerror=
  "alert(event.srcElement.src +
  '\n cannot be located.')">
</body>

 Show me 


Applies To

IMG, LINK, OBJECT, SCRIPT, STYLE, window

See Also

onerrorupdate




Contents
HTML Elements
HTML Element Attributes
CSS Attributes
DOM Objects
DOM Object Properties
DOM Events Reference
DOM Methods Reference
DOM Collections Reference
 

Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph