Pausing youtube embedded video

I have a web application that I am building for a client. It has multiple pages that show and hide content when the user interacts with the flow. I am having an issue with the YouTube video embed continuing to play audio in the background because the display of the video is hidden but the content still persist on the page (similar to something you would see on a modal). I am looking for a JavaScript function that can target the iframe dom node and pause the video when clicked.

I have found older threads but I think the YoutTube API has been updated because non of them are working. Does anyone know how to achieve this is 2021 with vanilla JS? Thank You!!

Source: JavaSript – Stack Overflow

November 23, 2021
Category : News
Tags: DOM | iframe | javascript | youtube-iframe-api

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.