HTML Audio/Video DOM error Event
HTML Audio/Video DOM Reference
Example
Display an error message when an error occurs while loading the video:
var vid = document.getElementById("myVideo");
vid.onerror = function() {
alert("Error! Something went wrong");
};
Definition and Usage
The error event is triggered when an error occurs while loading the audio/video.
Tip: Events that affect the loading of media data include:
Browser support
The numbers in the table indicate the version number of the first browser to support the event.
| Events | |||||
|---|---|---|---|---|---|
| error | Yes | 9.0 | Yes | Yes | Yes |
Syntax
In HTML:
<
element
onerror="
myScript
">In JavaScript:
object
.onerror=function(){
myScript
};
In JavaScript, use the addEventListener() method:
object
.addEventListener("error",
myScript
);
Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.
Technical Details
| Supported HTML tags: | |
|---|---|
| Supported JavaScript objects: | Audio, Video |
HTML Audio/Video DOM Reference