Image onerrorEvent
Image Object
Definition and Usage
The onerror event is triggered when an error occurs during the loading of a document or an image.
Syntax
onerror="JavaScriptCode"
| Parameter | Description |
|---|---|
| JavaScriptCode | Required. Specifies the JavaScript to execute when the event occurs. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the onerror event
Example
Example
In this example, if an error occurs while loading an image, a dialog box is displayed:
<img src="image.gif.html" onerror="alert('The image could not be loaded.')">
Try it Yourself »
Image Object Other Extensions