onloadstart
The onloadstart event is triggered when the browser begins loading an audio or video file.
onloadstart event
The onloadstart
event attribute runs a script when the media starts loading. It is commonly used with <audio>
and <video>
elements to manage loading states.
Syntax
In HTML
index.html
<element onloadstart ="myScript">
In JS
script.js
object.onloadstart = function(){myScript};
addEventListener()
function is used. In JavaScript, the
script.js
object.addEventListener("loadstart ", myScript);
Example
::event-onloadstart
::
index.html
<!DOCTYPE html>
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onloadstart Event</h2>
<video controls onloadstart="myFunction()">
<source src="mov_bbb.mp4" type="video/mp4">
<source src="mov_bbb.ogg" type="video/ogg">
Your browser does not support video playback.
</video>
<p id="demo">Event has fired: </p>
<p>Video courtesy of <a href="https://institute.qarpeo.com" target="_blank">Tree</a>.</p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML += "Loading has started";
}
</script>
</body>
</html>
Values
Conclusion
The onloadstart
event is triggered when the browser starts loading an <audio>
or <video>
file. It is useful for managing loading states, especially with <audio>
and <video>
elements. This event helps run scripts at the beginning of the media loading process.