Horje
HTML onpause Attribute

Definition and Usage

The onpause attribute defines a script to be run when the audio/video is paused either by the user or programmatically.

Tip: The onplay attribute is used to define a script to run when the audio/video has been started or is no longer paused.


Applies to

The onpause attribute is part of the Event Attributes, and can be used on the following elements:

Elements Event
<audio> pause
<video> pause

Browser Support

The onpause attribute has the following browser support for each element:


How to Run "myFunction" if the audio is paused - HTML onpause Attribute

Audio Example. This example demonstrates how to use the "onpause" attribute on an AUDIO element.
index.html
Example: HTML
<!DOCTYPE html> 
<html> 
<body> 

<p>Play and pause the audio file.</p>

<audio id="myAudio" controls onpause="myFunction()">
  <source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
  <source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

<script>
function myFunction() {
  alert("The audio file has been paused");
}
</script> 

<p>This example demonstrates how to use the "onpause" attribute on an AUDIO element.</p>

</body> 
</html>

Output should be:

How to Run "myFunction" if the audio is paused - HTML onpause Attribute

How to Run "myFunction" if the video is paused - HTML onpause Attribute

Video Example. This example demonstrates how to use the "onpause" attribute on a VIDEO element.

index.html
Example: HTML
<!DOCTYPE html> 
<html> 
<body> 

<p>Play and pause the video.</p>

<video id="myVideo" width="320" height="176" controls onpause="myFunction()">
  <source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/mp4">
  <source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/ogg">
  Your browser does not support HTML5 video.
</video>

<script>
function myFunction() {
  alert("The video has been paused");
}
</script> 

<p>This example demonstrates how to use the "onpause" attribute on a VIDEO element.</p>

<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>

</body> 
</html>

Output should be:

How to Run "myFunction" if the video is paused - HTML onpause Attribute




html onpause attribute

Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference