How to embed an autoplaying YouTube video in an iframe?
This works in Chrome but not Firefox 3.6 (warning: RickRoll video):
<iframe width="420" height="345" src="http://www.youtube.com/embed/oHg5SJYRHA0?autoplay=1" frameborder="0" allowfullscreen></iframe>
The JavaScript API for iframe embeds exists, but is still posted as an experimental feature.
UPDATE: The iframe API is now fully supported and "Creating YT.Player objects - Example 2" shows how to set "autoplay" in JavaScript.
Embedded YouTube iframes No Longer Autoplay
Major browser have disabled these features due to general abuse.
https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
https://blog.mozilla.org/firefox/block-autoplay/
YouTube checks upon loading whether it has permission to play how it wants to play the video. It will only autoplay if it has proper permission. The default in recent Chrome and Firefox builds is to only allow video - no sound. Adding &mute=1
the the youtube URL allows (muted) autoplay. This works if you don't necessarily need the sound, if you do then you will have to make the user click play themselves.
Applying this to the embed in your example:<iframe allow="autoplay" frameborder="0" allowfullscreen="" src="https://www.youtube.com/embed/sapLz6NjvJk?autoplay=1&mute=1&origin=https://OurWebsiteDomain" title="Bug Week " height="278" data-ytbridge="vidSurrogate2" style="width: 100%;"></iframe>
How can I autoplay a video using the new embed code style for Youtube?
Just put "?autoplay=1" in the url the video will autoload.
So your url would be:http://www.youtube.com/embed/JW5meKfy3fY?autoplay=1
In case you wanna disable autoplay, just make 1
to 0
as?autoplay=0
Youtube embedded video autoplay
It's the browser blocking autoplay(with sound) by default.
https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
It was finally implemented a few months ago. You can still use autoplay, but the video will need to be muted.
Notice the added mute=1 in the embed below. It will autoplay, but it breaks if you remove it.
<iframe width="560" height="315" src="https://www.youtube.com/embed/nwe76N7J0EI?rel=0&autoplay=1&mute=1" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
Why isn't my YouTube link autoplaying within an iframe in Chrome?
As mentioned in the comments, most modern browsers block autoplay videos these days unless they are muted. Just change your iFrame code to this
<iframe src="https://www.youtube.com/embed/SjVwyhbUUXE?autoplay=1&mute=1" width="100%" height="100%" frameborder="0" align="center"></iframe>
Related Topics
Getting Value of HTML Checkbox from Onclick/Onchange Events
Submit Form and Stay on Same Page
Get Iframe'S Document, from JavaScript in Main Document
Toggle Show/Hide Div With Button
How to Access CSS Generated Content With JavaScript
Like Button Ajax in Ruby on Rails
Why Is Document.Write Considered a "Bad Practice"
Disable Same Origin Policy in Chrome
Html "Overlay" Which Allows Clicks to Fall Through to Elements Behind It
Call JavaScript Function After Script Is Loaded
How to Get the Onclick Calling Object
Stop an Input Field in a Form from Being Submitted
Bootstrap Modal Appearing Under Background
Add/Remove Class With Jquery Based on Vertical Scroll
Changing Width Property of a :Before CSS Selector Using Jquery
Using Selenium to Imitate Dragging a File Onto an Upload Element