onpause
The onpause event in HTML is triggered when media playback is paused, allowing developers to perform specific actions in response.
onpause event
The onpause
event attribute in HTML is triggered when media playback is paused, like with <audio>
or <video>
elements. It lets developers run specific actions or scripts in response to the pause event.
Syntax
In HTML
index.html
<element onpause ="myScript">
In JS
script.js
object.onpause = function(){myScript};
addEventListener()
function is used. In JavaScript, the
script.js
object.addEventListener("pause ", myScript);
Example
::event-onpause
::
index.html
<!DOCTYPE html>
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onpause Event</h2>
<p>Assign an "onpause" event to a video element.</p>
<p>Play and pause the video.</p>
<video width="320" height="240" controls onpause="myFunction()">
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "The video was paused.";
}
</script>
</body>
</html>
Values
Conclusion
The onpause
event in HTML is triggered when media playback is paused, allowing developers to take specific actions. It is commonly used with <audio>
and <video>
elements. This event enables the execution of scripts in response to the pause action, improving user interaction.