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




ondurationchange attribute in html

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

  • The ondurationchange attribute triggers when duration change in a video/audio.
  • Default value of duration is “NaN” if it changed to a time duration the ondurationchange event occurs.

Syntax for ondurationchange attribute in HTML:

<audio ondurationchange="script">

Applies To:

Elements Attribute
<audio> ondurationchange
<video> ondurationchange

Attribute Values:

Value Description
script The script to be run on ondurationchange

Sample Coding for ondurationchange Attribute in HTML:

Tryit<!DOCTYPE html>
<html>
          <head>
          <title>Wikitechy ondurationchange attribute</title>
          </head>
 <body>
        <audio controls ondurationchange="durationChange(this)">
        <source src="welcome.wav" type="audio/wav">
        <source src="welcome.mp3" type="audio/mp3">
        </audio>
        <script>
        function durationChange (obj)
        {
             alert("Total Duration of Audio in Seconds :" + obj.duration);
        }
        </script>
</body>
</html>

Code Explanation for ondurationchange Attribute in HTML:

 ondurationchange Attribute Code Explanation

  1. ondurationchange attribute used to trigger an event when duration of the audio changed.
  2. “this” keyword used to pass the audio object to the JavaScript function.
  3. durationChange JavaScript function got the audio object as “obj”.
  4. obj.duration used to get the duration of the audio object.

Output for ondurationchange Attribute in HTML:

ondurationchange Attribute Tag Output

  1. The output shows "Total Duration of Audio in Seconds " in an alert message.

Browser Support for ondurationchange Attribute in HTML:

Yes 9.0 Yes Yes Yes

Related Searches to ondurationchange Attribute in html