HTML onerror Attribute
Example
<img src="image.png" onerror="myFunction()">
<script>
function myFunction() {
alert("Unable to load the image.");
}
</script>
Meaning
The onerror attribute is used to capture various events generally related to communication using Ajax, though may apply to arbitrary URL loading using media elements like images, audio, and video. This attribute is also used for catching script related errors.
Standard Syntax
<element onerror="script">
Browser Support
Status
Applies to:
The onerror attribute can be used on the following element:
Element | Attribute |
---|---|
<audio> | onerror |
<body> | onerror |
<embed> | onerror |
<img> | onerror |
<link> | onerror |
<object> | onerror |
<script> | onerror |
<video> | onerror |
Attribute Values
Value | Description |
---|---|
script | Specifies the script to be run on onerror |