Horje
HTML onerror Event Attribute
The  onerror event attribute is a global HTML attribute that executes a script when an external file or resource fails to load. It is most commonly used on <img> , <script> , and <link> elements to handle broken images, missing scripts, or stylesheet errors. 

Example of HTML onerror Event Attribute

It will alert that an error occured while loading the video.
index.html
Example: HTML

<!DOCTYPE html>
<html>
<head> <title>onerror event attribute</title> <style> body { text-align: center; } h1 { color: green; } </style>
</head>
<body> <img src=
"https://horje.com/avatar.png" onerror="myFunction()"> <h1>Horje</h1> <h2>onerror event attribute</h2> <script> function myFunction() { console.log("The image could not be loaded") } </script>
</body>
</html

Output should be:

Example of HTML onerror Event Attribute

Definition and Usage of HTML onerror Event Attribute

The error event occurs when an error occurred during the loading of an audio/video.

Tip: Related events that occurs when there is some kind of disturbance to the media loading process, are:


Browser Support of HTML onerror Event Attribute

The numbers in the table specify the first browser version that fully supports the event.

Browser Support of HTML onerror Event Attribute

Syntax of HTML onerror Event Attribute

< element onerror=" script ">

Attribute Values of HTML onerror Event Attribute

Value Description
script The script to be run on error

Technical Details of HTML onerror Event Attribute

Supported HTML tags: <audio> and <video>




html event attributes

Related Articles
List of Media Events HTML Media Events Attribute
HTML onabort Event Attrribute HTML Media Events Attribute
HTML oncanplay Event Attribute HTML Media Events Attribute
HTML oncanplaythrough Event Attribute HTML Media Events Attribute
HTML ondurationchange Event Attribute HTML Media Events Attribute
HTML onended Event Attribute HTML Media Events Attribute
HTML onerror Event Attribute HTML Media Events Attribute
HTML onloadeddata Event Attribute HTML Media Events Attribute
HTML onloadedmetadata Event Attribute HTML Media Events Attribute
HTML onloadstart Event Attribute HTML Media Events Attribute

Single Articles
Example of HTML onerror Event Attribute HTML Media Events Attribute
Definition and Usage of HTML onerror Event Attribute HTML Media Events Attribute
Browser Support of HTML onerror Event Attribute HTML Media Events Attribute
Syntax of HTML onerror Event Attribute HTML Media Events Attribute
Attribute Values of HTML onerror Event Attribute HTML Media Events Attribute
Technical Details of HTML onerror Event Attribute HTML Media Events Attribute

Type :
Develop
Category :
Web Tutorial
Sub Category :
HTML Media Events Attribute
Uploaded by :
Admin


Read Article
https://horje.com/learn/1434/reference