ontimeupdateEvent

事件对象参考手册Event Object

Example

Execute JavaScript when the current playback position changes:

<video ontimeupdate="myFunction()">

Try it yourself »

More examples are included at the bottom of this article.


Definition and Usage

The ontimeupdate event is triggered when the current playback position of the video/audio changes.

This event is invoked through the following ways:

  • Playing the video/audio
  • Repositioning the playback position of the video/audio.

Tip:This event is usually used with the Video object's currentTimeproperty, which returns the current playback position of the audio/video.


Browser Support

The numbers in the table specify the first browser version that fully supports the event.

Event
ontimeupdate Yes 9.0 Yes Yes Yes


Syntax

In HTML:

<element ontimeupdate="myScript">Try it yourself

In JavaScript:

object.ontimeupdate=function(){myScript};Try it yourself

In JavaScript, using the addEventListener() method:

object.addEventListener("seeking", myScript);Try it yourself

Note:Internet Explorer 8 and earlier IE versions do not supportaddEventListener()the method.


Technical Details
Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <audio>, <video>


Examples

More Examples

Example

Execute JavaScript when the user starts playing audio or repositions the audio playback position:

<audio ontimeupdate="myFunction()">

Try it yourself »

Example

Use the currentTime property to set the current playback position to 5 seconds:

document.getElementById("myVideo").currentTime = 5;

Try it yourself »


事件对象参考手册Event Object Other Extensions