Javascript DOM onended Event

Introduction

Execute a JavaScript when an audio has ended:

This example demonstrates how to assign an "onended" event to an audio element.

Press play and wait for the audio to end.

View in separate window

<!DOCTYPE html>
<html>
<body>
<audio controls onended="myFunction()">
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>//from ww  w  . j av a  2  s. c  o  m

<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "The video has ended";
}
</script>

</body>
</html>

The onended event occurs when the audio/video has reached the end.

Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <audio> and <video>



PreviousNext

Related