HTML Audio/Video DOM endedEvents

HTML Audio/Video DOM Reference Manual

Example

Popup notification after audio playback completes:

var aud = document.getElementById("myAudio");
aud.onended = function() {
alert("Audio playback complete");
};

Try it Yourself »

This article contains more examples at the bottom.


Definition and Usage

The ended event is triggered when audio/video playback has completed.

This event is typically used to show playback completion messages, such as "Thanks for listening," "Thanks for watching," and so on.


Browser Support

The numbers in the table indicate the version number of the first browser that supports this event.

Events
ended Yes 9.0 Yes Yes Yes


Syntax

In HTML:

<audio|video onended="myScript">Try it Yourself

In JavaScript:

audio|video.onended=function(){myScript};Try it Yourself

In JavaScript, using the addEventListener() method:

audio|video.addEventListener("ended", myScript);Try it Yourself

Note:Internet Explorer 8 and earlier IE versions of browsers are not supportedaddEventListener()method.


Technical Details
Supported HTML tags: <audio> and <video>
Supported JavaScript objects: Audio, Video


Examples

More Examples

Example

Popup notification after video playback completes:

var vid = document.getElementById("myVideo");
vid.onended = function() {
    alert("The video has ended");
};

Try it Yourself »


HTML Audio/Video DOM Reference Manualother extensions