Stop all video youtube via javascript

(chans) #1

I tried to use this javascript to stop all iframe youtube but it not work. (37.8 KB)

Help me please, I dont know where I wrong
Thank you so much.

(Hans-Gerd Claßen) #2


first: you should not nest iframes within a widget which itsself is an iframe too. just past the embedcode within a regular rectangle.

second: use this code provided at github unchanged. you’ve changed the queryselector from htmlelement to class …

third: give an unique id to every hypeelemnt that holds an iframe …

fourth: then run …

good luck :slight_smile:

(chans) #3

If I use many rectangle, my app is very slow. I dont know why.
I dont want give unique ID for every iframe, I want to use class for all of iframe.

(Hans-Gerd Claßen) #4

then you’ll need an iteration within the function … as the current paramter is an element and not a collection

(Hans-Gerd Claßen) #5
var yourCustomClassForVideos = 	'yourCustomClass';
var labeledIframes = document.getElementsByClassName(yourCustomClassForVideos), 0 );//labeled elements as array
labeledIframes.forEach(function (item) {//iterate thru array
  var embed = item.querySelector('iframe');//get optional first embedded iframe within labeled hypeelement
 if(embed) embed.src = embed.src //if iframe exist this'll reload ...

(chans) #6

Sorry , Can you create a Hype file demo?
I tested on Hype with multi iframe but it not work.

(Hans-Gerd Claßen) #7

you’ll take and place a widget
set your embedcode

place the button
attach a behaviour that’ll excute above js

don’t forget to set class: yourCustomClass

should work :slight_smile: