2

I am trying to implement a embedded youTube link to a custom Html page and setting it to autoplay but as I open my Homepage video doesn't play and only played when clicked .

<iframe width="1560" height="415" src="https://www.youtube.com/../?autoplay=1"
                            frameborder="0" allowfullscreen></iframe>

I want to make it responsive.

  • That's not what "responsive" means in web dev FYI. – Wendelin Mar 16 '21 at 13:51
  • 1
    Does this answer your question? [How to embed an autoplaying YouTube video in an iframe?](https://stackoverflow.com/questions/7281765/how-to-embed-an-autoplaying-youtube-video-in-an-iframe) – Wendelin Mar 16 '21 at 13:53

3 Answers3

0

I'm not sure if this helps or even works but have you tried something like this?

$(document).ready(function() {
    $(iframe).click();
});
Rendolph
  • 433
  • 2
  • 9
0

You said https://www.youtube.com/../?autoplay=1

Get rid of that slash before the question mark

I think it should be https://www.youtube.com/viddata?autoplay=1 instead.

Maybe thats why its not playing

Coder2195
  • 268
  • 2
  • 13
0

Get rid of the slash in the URL like Coder2195 said (https://www.youtube.com/viddata?autoplay=1). Also try to add this script to the HTML file:

<script>
window.onload = function() {
  var videoElement = document.getElementById("videoElement");
  videoElement.click()
}
</script>

And make the iframe element have a custom id:

<iframe id="videoElement" width="1560" height="415" src="https://www.youtube.com/../?autoplay=1" frameborder="0" allowfullscreen></iframe>
Tyler Selden
  • 281
  • 2
  • 14