CSS Portal

HTML onloadeddata Event Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
onloadeddata
HTML Event AttributeThis event attribute is supported by all modern browsers.
Updated 14th October 2023

Description

The HTML onloadeddata event attribute is fired when the first frame of an audio or video element has finished loading. This does not guarantee that enough data is available to begin playing the media, but it does indicate that the browser has at least enough data to display the first frame.

The onloadeddata event is typically used to start preloading the next frame of the media, or to perform other tasks that require the first frame to be loaded. For example, you could use the onloadeddata event to start displaying a loading animation, or to disable a play button until the first frame is loaded.

To use the onloadeddata event attribute, simply add it to an audio or video element and specify the name of a JavaScript function to be called when the event is fired. For example:

<video onloadeddata="myFunction()">
  <source src="my_video.mp4" type="video/mp4">
</video>

The myFunction() function will be called when the first frame of the video has finished loading.

Here is an example of a JavaScript function that you could use to handle the onloadeddata event:

function myFunction() {
  // Start preloading the next frame of the video
  video.load();

  // Enable the play button
  playButton.disabled = false;
}

The onloadeddata event is a useful event for controlling the loading and playback of audio and video elements. By using the onloadeddata event, you can ensure that your media elements are ready to play before displaying them to the user.

Syntax

<element onloadeddata="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE HTML>
<html>
<body>

<audio id="myAudio" controls onloadeddata="myFunction()">
<source src="audio.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>

<p>Play audio file:</p>

<script>
function myFunction() {
alert("EXAMPLE: Data uploaded");
}
</script>

<p>This example shows how to use the onloadeddata attribute for an AUDIO element.</p>

</body>
</html>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML onloadeddata 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

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee