Trying to use a embedded youTube link for auto play in custom HTML

Viewed 68

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.

3 Answers

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

$(document).ready(function() {
    $(iframe).click();
});

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

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>
Related