![]() |
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:
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
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:
The numbers in the table specify the first browser version that fully supports the event.
< element onerror=" script ">
Value | Description |
---|---|
script | The script to be run on error |
Supported HTML tags: | <audio> and <video> |
---|
html event attributes |
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 |
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