Execute a JavaScript if an error occurs when loading an image:
<img src="image.gif" onerror="myFunction()">
Try it Yourself »
The onerror event is triggered if an error occurs while loading an external file (e.g. a document or an image).
Tip: When used on audio/video media, related events that occurs when there is some kind of disturbance to the media loading process, are:
Event | |||||
---|---|---|---|---|---|
onerror | Yes | Yes | Yes | Yes | Yes |
In JavaScript, using the addEventListener() method:
object.addEventListener("error",
myScript);
Try it Yourself »
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | UiEvent if generated from a user interface, Event otherwise |
HTML tags: | <img>, <input type="image">, <object>, <link>, and <script> |
DOM Version: | Level 2 Events |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!