Javascript DOM onpause Event on <audio> element

Introduction

Execute a JavaScript when an audio has been paused:

This example demonstrates how to assign an "onpause" event to an audio element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>Play and pause the video.</p>

<audio controls onpause="myFunction()">
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>/*w  ww.j  a  v a  2  s. com*/

<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "The audio was paused";
}
</script>

</body>
</html>



PreviousNext

Related