1

I'm trying to make a Rick Roll sample app, but when I use YouTube embed feature, the autoplay parameter causes the YouTube video to load showing the message "The video is unavailable". When I pass ?autoplay=0 or don't pass autoplay at all, the embed works as expected. I'm experiencing this in both Chrome and Firefox. Any thoughts on how to fix or get around this?

<!DOCTYPE html>
<html>
  <body>
    <button onclick="openWin()">Open "myWindow"</button>
  <script>
    var myWindow;

    function openWin() {
      myWindow=window.open("", "myWindow", "width=570, height=330");
      myWindow.document.write('<iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ?autoplay=1" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>');
      myWindow.setInterval(function() {
        moveWin();
      }, 1000);
    }

    function moveWin() {
      var x = getRandomNumber();
      var y = getRandomNumber();

        myWindow.moveTo(x, y);
        myWindow.focus();
    }

    function getRandomNumber() {
      return Math.floor(Math.random() * 500);
    }
  </script>

  </body>
</html>
Shwheelz
  • 445
  • 3
  • 8
  • 18
  • Must be video related see the url over [here](https://stackoverflow.com/a/3433300/6160662) – Viney Jul 04 '18 at 03:08
  • Yea, could be video related. I tried with another video, and the video showed up, but it still didn't autoplay. I also tried with ?autoplay=true and it still makes me press the play button – Shwheelz Jul 04 '18 at 04:13

0 Answers0