Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

onerror event

onerror event

Event Object Reference Event Object

Example

Execute JavaScript if an error occurs while loading an image:

<img src="image.gif" onerror="myFunction()">

Try it »


Definition and Usage

The onerror event is triggered when an error occurs while loading an external file (document or image).


Browser support

Events
onerror Yes Yes Yes Yes Yes

Syntax

In HTML:

<

element

onerror="

myScript

">

Try it

In JavaScript:

object

.onerror=function(){

myScript

};

Try it

In JavaScript, use the addEventListener() method:

object

.addEventListener("error",

myScript

);

Try it

Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.


Technical Details

Does it support bubbling: No
Is it cancelable: No
Event type: If it is generated on the user interface, it is a UIEvent; otherwise it is an Event.
Supported HTML tags: , , ,