Javascript DOM ontimeupdate Event via HTML Tag ontimeupdate attribute

Introduction

In this example, we assign an "ontimeupdate" event to a video element.

When the user starts to play the video, or skips to a new position in the video, a function is triggered.

It will display the current position (in seconds) of the video playback.

View in separate window

<!DOCTYPE html>
<html>
<body>

<video controls ontimeupdate="myFunction(this)">
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>//from   w  w  w .jav  a2s.com

<p>Playback position: <span id="demo"></span></p>

<script>
function myFunction(event) {
  // The currentTime property returns the current position of the audio/video playback
  document.getElementById("demo").innerHTML = event.currentTime;
}
</script>

</body>
</html>
Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <audio> and <video>



PreviousNext

Related