|
|
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. |
<!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 |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Media Events Attribute |
Uploaded by: | Admin |
Read Articlehttps://develop.horje.com/learn/1434/reference