Javascript examples for DOM HTML Element:Video
The autoplay property sets or gets whether a video should start playing as soon as it is loaded.
This property reflects the <video> autoplay attribute.
Set the autoplay property with the following Values
Value | Description |
---|---|
true|false | Sets whether a video should automatically start playing as soon as it is loaded |
A Boolean, returns true if the video automatically starts playing, otherwise it returns false
Default Value is false
The following code shows how to check if the video started to play as soon as it was ready:
<!DOCTYPE html> <html> <body> <video id="myVideo" width="320" height="240" controls> <source src="your.mp4" type="video/mp4"> <source src="your.ogg" type="video/ogg"> Your browser does not support the video tag. </video><br> <button onclick="enableAutoplay()" type="button">Enable autoplay</button> <button onclick="disableAutoplay()" type="button">Disable autoplay</button> <button onclick="checkAutoplay()" type="button">Check autoplay status</button> <script> var x = document.getElementById("myVideo"); function enableAutoplay() {/* w w w .jav a2 s .c om*/ x.autoplay = true; x.load(); } function disableAutoplay() { x.autoplay = false; x.load(); } function checkAutoplay() { console.log(x.autoplay); } </script> </body> </html>