HTML Audio/Video DOM ended Event
HTML Audio/Video DOM Reference
Example
Display a message when audio playback ends:
var aud = document.getElementById("myAudio");
aud.onended = function() {
alert("Audio playback complete");
};
Try it »
The bottom of this article contains more examples.
Definition and Usage
The ended event is triggered when the audio/video playback has finished.
This event is often used to display a completion message such as "Thank you for listening", "Thank you for watching", etc.
Browser support
The numbers in the table indicate the version number of the first browser to support the event.
| Events | |||||
|---|---|---|---|---|---|
| ended | Yes | 9.0 | Yes | Yes | Yes |
Syntax
In HTML:
<
audio|video
onended="
myScript
">Try it
In JavaScript:
audio|video
.onended=function(){
myScript
};
Try it
In JavaScript, use the addEventListener() method:
audio|video
.addEventListener("ended",
myScript
);
Try it
Note: Browsers such as Internet Explorer 8 and earlier IE versions do not support addEventListener() method.
Technical Details
| Supported HTML tags: | |
|---|---|
| Supported JavaScript objects: | Audio, Video |
More examples
Example
Display a message when video playback ends:
var vid = document.getElementById("myVideo");
vid.onended = function() {
alert("The video has ended");
};
Try it »
HTML Audio/Video DOM Reference