Javascript DOM ontimeupdate Event via HTML Tag ontimeupdate function

Introduction

In JavaScript:

object.ontimeupdate = function(){
       myScript};

In this example, we use the HTML DOM to 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 id="myVideo" controls>
  <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.j  a v a 2 s . c  om

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

<script>
// Get the video element with id="myVideo"
var x = document.getElementById("myVideo");

x.ontimeupdate = function() {myFunction()};

function myFunction() {
  document.getElementById("demo").innerHTML = x.currentTime;
}
</script>
</body>
</html>
Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <audio> and <video>



PreviousNext

Related