Embedded YouTube video does not stop in Chrome and IE

Few topics on this, but no answers for me.

Attaching a youtube video in an overlay div:

   <div id="blanket" style="display:none;">
     </div>
        <div id="popUpDiv" style="display:none;">
        <a href="#" onclick="popup('popUpDiv')">Close</a>     
        <iframe width="480" height="390" src="https://www.youtube.com/embed/G5AuItKv?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>                                       
        </div>

In Firefox, when I close the window, the video stops, but not in Chrome or Internet Explorer.

Is there any simple javascript that I can use to stop it when the user clicks the Close button?

TIA

Edit:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<a href="#" onclick="javascript:ytplayer.stop()">Close</a>

 <iframe width="480" height="390" src="http://www.youtube.com/e/PE1il5znICA?enablejsapi=1&version=3&playerapiid=ytplayer" frameborder="0"  allowfullscreen></iframe>


 <script type="text/javascript">
function onYouTubePlayerReady(playerId) {
    ytplayer = document.getElementById("ytplayer");
}

function stop() {
  if (ytplayer) {
    ytplayer.stopVideo();
  }
}
</script>
</body>
</html>
+5
source share
2 answers

Youtube javascript api, , . api, : &enablejsapi=1 URL- src, javascript. :

function onYouTubePlayerReady(playerId) {
    ytplayer = document.getElementById("nameofplayer");
}

:

function stop() {
  if (ytplayer) {
    ytplayer.stopVideo();
  }
}

stop(); onclick .

javascript apt youtube .

+3

HTML5. Iframe API Youtube, JavaScript api.

:

<iframe width="480" height="390" src="http://www.youtube.com/e/PE1il5znICA?enablejsapi=1&version=3&playerapiid=ytplayer" frameborder="0"  allowfullscreen></iframe>

swfobject.embedSWF("http://www.youtube.com/e/PE1il5znICA?enablejsapi=1&version=3&playerapiid=ytplayer","ytplayer", "480", "390", "8", null, null, params, atts);

Exemple:

div html:

<div id="ytplayer">
<p>You need Flash player and JavaScript enabled to view this video.</p>
</div>

script :

<script type="text/javascript">

    function onYouTubePlayerReady(playerId){ytplayer = document.getElementById("ytplayer");}
         var params = { allowScriptAccess: "always" };var atts = { id: "ytplayer" };


         swfobject.embedSWF("http://www.youtube.com/e/videoID?enablejsapi=1&version=3&playerapiid=ytplayer","ytplayer", "425", "356", "8", null, null, params, atts);

         function stop() {if (ytplayer) {ytplayer.stopVideo();}}
    </script>

Work for me.

+1
source

All Articles