html tutorial - oncanplay Attribute in HTML - html5 - html code - html form




Oncanplay attribute in html

Learn html - html tutorial - Oncanplay attribute in html - html examples - html programs

  • The oncanplay attribute is used to execute a script when the browser can starts playing the specific media file.

Syntax for oncanplay attribute in HTML:

<element oncanplay="script">

Differences between HTML 4.01 and HTML5 for oncanplay attribute:

HTML 4.01

HTML 5

Applies To:

Elements Attribute
<audio> form
<video> form

Attribute Values:

Value Description
script The script to be run on oncanplay

Sample Coding for oncanplay Attribute in HTML:

Tryit<!DOCTYPE html>
<html>
        <head>
        <title>Wikitechy oncanplay  attribute</title>
        </head>
 <body>
        <video width="320" height="240" controls oncanplay="onCanPlay()">
        <source src="hibiscus.mp4" type="video/mp4">
        </video>
        <script>
        function onCanPlay()
        {
          alert("Wikitechy Video Can Play Now!");
        }
        </script>
</body>
</html>

Code Explanation for oncanplay Attribute in HTML:

 oncanplay  Attribute Code Explanation

  1. <video> tag is used to embed a video file in the HTML Document.
  2. The oncanplay attribute is used to trigger an event when the video can be ready to play.
  3. The JavaScript function oncanplay is used to display an alert message.

Output for oncanplay Attribute in HTML:

oncanplay Attribute Tag Output

  1. The output shows the video file can be played, so the alert message displayed as “Wikitechy Video Can Play Now!”.

Browser Support for oncanplay Attribute in HTML:

Yes 9.0 Yes Yes Yes

Related Searches to oncanplay attribute in html