2017-05-17 4 views
0

Ich möchte aufhören, ein Youtube Video zu spielen, wenn ich auf ein div klicke. Ich weiß nicht, wie ich das machen soll und es funktioniert nicht, wenn ich Informationen online verwende. Das habe ich gemacht!Stop iframe youtube video

ich den youtube iframe API verknüpft habe:

<script src="https://www.youtube.com/iframe_api"></script> 

Dann habe ich einen iframe in meiner HTML-Datei:

<iframe id="vid" src="https://www.youtube.com/embed/P2lm356ycwY?enablejsapi=1" frameborder="0" allowfullscreen></iframe> 

Dann in meinem Skript habe ich diesen Code:

$("#popupvid").click(function(){ 
    $("#popupvid").css("display","none"); 
    $("#vid").css("display","none"); 

    //Code to make the youtube video stop here: 

}); 

Was muss ich schreiben, damit das Video hier aufhört! Vielen Dank im Voraus!

+1

http://stackoverflow.com/questions/13598423/stop-all-playing- Iframe-Videos-auf-Klick-ein-Link-Javascript – mxr7350

+0

@ mxr7350 Vielen Dank! – robeng

Antwort

0
$(document).ready(function() { 
    $("iframe").mouseover(function() { 
     $("iframe").each(function() { 
      $(this)[0].contentWindow.postMessage('{"event":"command","func":"stopVideo","args":""}', '*'); 
     }); 
    }); 
}); 

werden dadurch alle Videos, ändern die Maus über das Ereignis beenden zu klicken und die erste iframe auf die ID des div