Stop multiple <iframe> embedded videos

The information here: “Stop multiple videos” is useful if you want to stop multiple videos with a given class/tag name, however I am currently working with <iframe> embedded videos, and needed them to stop playing when moving between scenes.

Here is a simple technique to stop all iframe embedded videos from playing, by setting the iframe src value to itself.

var elements = document.getElementsByTagName('iframe');
for (var i=0; i<elements.length; i++) {
var src = elements[i].src;
elements[i].src = src;    
}
2 Likes

not to stop the video, but setting a new src to the iFrames will end up in reloading . . . not userfriendly :wink: but quick hack :slight_smile:

That is true! It is a bit of a hack. I was not able to find a more elegant solution :slight_smile:

1 Like