Execute a script when the media has reached the end of HTML?


Use the onended attribute in HTML to execute a script when the media has reached the end in HTML . You can add messages like “Thank you for watching”, “Stay tuned!”, etc.

Example

You can try to run the following code to implement the onended attribute −

<!DOCTYPE HTML>
<html>
   <body>
      <video width = "300" height = "200" controls onended = "display()">
         <source src = "/html5/foo.ogg" type = "video/ogg" />
         Your browser does not support the video element.
      </video>
      <script>
         function display() {
            alert ("Thank you for watching! Stay tuned!");
         }
      </script>
   </body>
</html>

Updated on: 03-Mar-2020

50 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements