onwaiting

The onwaiting event in HTML occurs when media playback is paused due to buffering, enabling scripts to handle loading states.

onwaiting event

The onwaiting event attribute activates a script when media playback is paused due to buffering or waiting for data. It's helpful for showing loading indicators or managing playback interruptions.

Syntax

In HTML

index.html
<element onwaiting ="myScript">

In JS

script.js
object.onwaiting  = function(){myScript};

In JavaScript, the addEventListener() function is used.

script.js
object.addEventListener("waiting ", myScript);

Example

::event-onwaiting ::
index.html
<!DOCTYPE html>
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onwaiting Event</h2>

<p>Assign an "onwaiting" event to a video element:</p>

<video controls onwaiting="myFunction()">
  <source src="mov_bbb.mp4" type="video/mp4">
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>

<p>Video courtesy of <a href="https://institute.qarpeo.com" target="_blank">Tree</a>.</p>

<p>Play the video.</p>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Buffering";
}
</script>

</body>
</html>

Values

Example

This logs a message to the console when the <video> playback is paused because of buffering.

Conclusion

The onwaiting event is triggered when media playback is paused due to buffering or waiting for data. It allows developers to manage loading states, such as displaying a loading indicator. This enhances the user experience by handling interruptions in playback.