HTML oncanplaythrough Event Attribute
Description
The oncanplaythrough HTML event attribute specifies a function to be executed when the browser estimates it can play through the specified audio/video without having to stop for buffering.
This event is typically used to start playing the media when it is ready, or to enable features such as fast-forwarding and rewinding. It is important to note that the oncanplaythrough event is not fired when the media has finished loading, but rather when the browser estimates that it has enough data to play through the entire media file without having to stop for buffering.
The oncanplaythrough event can be specified using the following syntax:
<audio|video oncanplaythrough="functionName()">
Where functionName() is the name of the function to be executed when the event is fired.
The following is an example of how to use the oncanplaythrough event attribute:
<video oncanplaythrough="playVideo()">
<source src="video.mp4" type="video/mp4">
</video>
<script>
function playVideo() {
var video = document.querySelector('video');
video.play();
}
</script>
In this example, the playVideo() function will be executed when the browser estimates it can play through the video.mp4 file without having to stop for buffering.
The oncanplaythrough event is a useful way to ensure that your media content is played smoothly and without interruption.
Syntax
<element oncanplaythrough="script">
Values
- scriptThe name of the script to use when the event has been triggered.
Example
Browser Support
The following information will show you the current browser support for the HTML oncanplaythrough event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.
This event attribute is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 14th October 2023
