Video preload Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Video


The preload property sets or gets the preload attribute of a video.

The <video> element is new in HTML5.

Set the preload property with the following Values

auto The author thinks that the browser should load the entire video when the page loads
metadata The author thinks that the browser should load only metadata when the page loads
none The author thinks that the browser should NOT load the video when the page loads

Return Value

A String, representing what data should be preloaded.

Possible return values are "auto", "metadata", or "none".

The following code shows how to check if and how the author thinks that the video should be loaded when the page loads:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction('none')">Video without preload</button>
<button onclick="myFunction('auto')">Video with preload</button>

function myFunction(p) {
    var x = document.createElement("VIDEO");
    x.setAttribute("controls", "controls");
    var y = document.createElement("SOURCE");
    y.setAttribute("src", "your.mp4");
    y.setAttribute("type", "video/mp4");
    x.appendChild(y);//w  ww.  ja  v a2s . c  o  m
    var z = document.createElement("SOURCE");
    z.setAttribute("src", "your.ogg");
    z.setAttribute("type", "video/ogg");

    // Set the preload property:
    x.preload = p;


<p><b>Note:</b> The preload attribute is not supported in IE.</p>


Related Tutorials