oncanplayEvent
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:
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> |

More Examples
Example
Execute JavaScript when the audio is ready to play:
<audio oncanplay="myFunction()">
Try it yourself »
Event Object Other Extensions