HTML - attributes - onended

revision:


Content

"onended" attribute : when audio/video has reached end syntax some examples


"onended" attribute : when audio/video has reached end

top

This event occurs when the audio/video has reached the end. It is useful for messages like "thanks for listening", "thanks for watching", etc.

The "onended attribute" is part of the event attributes and can be used on the following elements:<audio> and <video>


syntax

top

<element onended="script"></element >

script: the script to be run on onended


some examples

top

Play the audio file:

codes:
                    <audio style="margin-left:3vw;" id="myAudio" controls onended="endedFunc()">                                         
                        <source src="../../pics/horse.wav" type="audio/wav">
                        Your browser does not support the audio element.
                    </audio>
                    <p>  class="spec">Play the audio file:</p>
                    <script>
                        function endedFunc() {
                        alert("Thank you for listening");
                        }
                    </script> 
                

Play the video:

codes:
                    <video style="margin-left:3vw;" id="myVideo" width="320" height="176" controls onended="videoEnded()">
                        <source src="../../pics/Wuzhen-20-10_02.mp4" type="video/mp4">
                        Your browser does not support HTML5 video.
                    </video>
                    <script>
                        function videoEnded() {
                        alert("Thank you for watching");
                        }
                    </script>