asp.net.ph

Skip Navigation Links

onerror Event


Fires when an error occurs loading the object.

Syntax

Inline <element onerror = "handler" ... >
Script object.onerror = handler

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


Need a break ?
Suggested Reading

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph.

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