onerrorevent

事件对象参考手册Event Object

Examples

Execute JavaScript if an error occurs while loading an image:

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

Try it yourself »


Definition and Usage

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


Browser Support

Event
onerror Yes Yes Yes Yes Yes


Syntax

In HTML:

<element onerror="myScript">Try it yourself

In JavaScript:

object.onerror=function(){myScript};Try it yourself

In JavaScript, using the addEventListener() method:

object.addEventListener("error", myScript);Try it yourself

Note:Internet Explorer 8 and earlier IE versions do not supportaddEventListener()the method.


Technical Details

Does it support bubbling: No
Can it be canceled: No
Event type: If it is generated on the user interface, it is a UIEvent, otherwise it is an Event.
Supported HTML tags: <img>, <input type="image">, <object>, <script>, <style>


事件对象参考手册Event Object

Other extensions