In JavaScript:
object.onended = function(){
myScript};
This example uses the HTML DOM to assign an "onended" event to an audio element.
Press play and wait for the audio to end.
<!DOCTYPE html> <html> <body> <audio id="myAudio" controls> <source src="sound.ogg" type="audio/ogg"> <source src="sound.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio>/*from w w w. j a va 2 s .co m*/ <p id="demo"></p> <script> document.getElementById("myAudio").onended = function() {myFunction()}; function myFunction() { document.getElementById("demo").innerHTML = "The audio has ended."; } </script> </body> </html>
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
Supported HTML tags: | <audio> and <video> |