f/Javascript posted by rob - - Edited
Pause YouTube embedded videos when a new video is played

While I was cobbling this site together I never gave a lot of thought to what would happen if you had several YouTube videos on a page and the possibility that none or all of them could be playing at any given time! Ideally, there should be only one. That being said, I set out to find a solution for the problem.

https://itecnote.com/tecnote/pause-youtube-iframe-embed-when-playing-another/

With a little bit of google--fu it turns out the answer was fairly simple. The javascript above iterates through all the iframes on the page and filters the src attribute containing https://www.youtube.com.Next the script iterates through the resulting I frames and binds to the onStateChange so that when one video is played it pauses any other video that is currently playing.

I had found this link and incorporated it. I thought it would be a good idea to write it down before it got lost to my memory and the interwebs. You can check it out in the forums.

0 Comments
There are no comments yet. Login to start the conversation.
f/Javascript
Javascript related content

Created Jun 22, 2023

1
Member

Moderators
u/rob