Javascript DOM HTML Video autoplay Property set

Introduction

Enable autoplay, and reload the video:

View in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" width="100" height="100" controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video><br>
<p id="demo"></p>
<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 .  j a  va  2  s.  co  m
  x.autoplay = true;
  x.load();
}

function disableAutoplay() {
  x.autoplay = false;
  x.load();
}

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

</body>
</html>



PreviousNext

Related