Javascript DOM HTML Video autoplay Property

Introduction

Find out if the video started to play as soon as it was ready:

var x = document.getElementById("myVideo").autoplay;

Click the button to find out if the movie automatically started to play as soon as it was ready.

View in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" width="100" height="100" controls autoplay>
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>// w ww.j a va2s.c om
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myVideo").autoplay;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The autoplay property sets or gets whether a video should start playing as soon as it is loaded.

This property mirrors the <video> autoplay attribute.

Value Description
truevideo should start playing as soon as it is loaded
false Default. video should NOT start playing as soon as it is loaded

The autoplay property returns true if the video automatically starts playing, otherwise it returns false.




PreviousNext

Related