oncanplayEvent

事件对象参考手册Event Object

Example

Execute JavaScript when the video is ready to start playing:

<video oncanplay="myFunction()">

Try it yourself »

More examples can be found at the bottom of this article.


Definition and Usage

The oncanplay event is triggered when the user can start playing the video/audio (audio/video).

During the loading process of the video/audio (audio/video), the events are triggered in the following order:

  1. onloadstart
  2. ondurationchange
  3. onloadedmetadata
  4. onloadeddata
  5. onprogress
  6. oncanplay
  7. oncanplaythrough

Browser Support

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

Event
oncanplay Yes 9.0 Yes Yes Yes


Syntax

In HTML:

<element oncanplay="myScript">Try it yourself

In JavaScript:

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

In JavaScript, using the addEventListener() method:

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

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


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


Examples

More Examples

Example

Execute JavaScript when the audio is ready to play:

<audio oncanplay="myFunction()">

Try it yourself »


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