View video tutorial

HTML onstalled Attribute

HTML

The HTML onstalled attribute is an event handler used to specify a script that will run when the browser attempts to fetch media data, but the data is not available or the fetch process unexpectedly stops.

Definition and Usage


➔ The onstalled event is triggered when the browser tries to fetch media data (video or audio) but for some reason the data is not coming.

Syntax
//In HTML
<video controls onstalled="myFunction()" id="sample">
  <source src="video-source.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>

//In javascript
document.getElementById("sample").onstalled=function() {myFunction();};
//OR
document.getElementById("sample").addEventListener("stalled", myFunction);
//OR 
document.getElementById("sample").addEventListener("stalled", (event) => {
    myFunction();
 });

Applies to

This attribute can be used on the following element.

Attribute Element
onstalled <audio>, <video>

Example
<!DOCTYPE html>
<html>
<head>
    <title>HTML onstalled attribute example</title>
</head>
<body>
    <h3>HTML onstalled attribute example</h3>
    <p>If the data is not received, the stalled event will be triggered.</p>
    <!-- "https://mdn.github.io/learning-area/html/multimedia-and-embedding/video-and-audio-content/rabbit320.mp4" -->
    <video controls onstalled="myFunction(event)" id="sample">
        <source src="video-source-path.mp4" type="video/mp4">
        This browser does not support the video tag.
    </video>
    <script>
        //In javascript
        //document.getElementById("sample").onstalled=function() {myFunction();};
        //OR
        //document.getElementById("sample").addEventListener("stalled", myFunction);
        function myFunction(e) {            
            alert("Media data fetching has stalled");
        }
    </script>
</body>
</html>