Execute a script when the browser is unable to fetch the media data for whatever reason in HTML?


Use the onstalled attribute in HTML to execute a script when the browser is unable to fetch the media date.

The onstalled attribute can be used for the following elements −

<video>
<audio>

The following is the syntax for <video> −

<video onstalled ="script">

The following is the syntax for <video> −

<audio onstalled = "script">

Example

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

<!DOCTYPE HTML>
<html>
   <body>
      <video width = "300" height = "200" controls onstalled ="display()">
         <source src = "/html5/foo.ogg" type = "video/ogg" />
         <source src = "/html5/foo.mp4" type = "video/mp4" />
         Your browser does not support the video element.
      </video>
      <script>
         function display()
         {
            alert ("Sorry! Video isn't available right now!");
         }
      </script>
   </body>
</html>

Updated on: 24-Jun-2020

318 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements