add autoplay to youtube iframe on button click jquery not working

add autoplay to youtube iframe on button click jquery not working



I am using custom buttons to keep my design consistent. I have added a button which is layered on top of the iframe using the z-index property in CSS. Onclick the iframe reacts but does not begin to play. I have used this code on other websites and it worked fine.


iframe


z-index


iframe



This code works in Safari but not in Chrome. I am not sure if maybe I should try re-installing Chrome.



I have also added 1 other lines which I have tried (commented out). Can anyone suggest why this is not working on chrome?


$('#playLucid').click(function()
$('#playLucid').css('display', 'none');
//$("#expose").attr('src','https://www.youtube.com/embed/7bU-x8pJbig?autoplay=1');
$("#expose")[0].src += "?autoplay=1";
);






What type of element is #expose? Also note that Chrome has strict rules on when it will/will not allow a video to be auto played. I'd suggest you read this guide to ensure you're following them fully.

– Rory McCrossan
Sep 7 '18 at 13:46



#expose






@RoryMcCrossan <div class="col-md-6 col-sm-12 attitude"> <iframe class="expose" id="expose" src="youtube.com/embed/7bU-x8pJbig" frameborder="0"></iframe> </div>

– Alex
Sep 7 '18 at 14:08






here is the HTML

– Alex
Sep 7 '18 at 14:08




1 Answer
1



This May Work:


<iframe type="text/html"
src="https://www.youtube.com/embed/..?autoplay=1" frameborder="0"
allow="autoplay">
</iframe>



If it doesn't work, try adding mute=1 or muted=1:


mute=1


muted=1


src="https://www.youtube.com/embed/..?autoplay=1&mute=1






I needed to add "allow="autoplay". This helped me find the solution. So thank you.

– Alex
Sep 7 '18 at 14:40



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)