I currently use the following script to pause the youtube video:
HTML:
<span onClick="stopVideo();" class="wmg-close"></span>
<div id="player<?= $dAgenda['id'];?>"></div>
JavaScript within the PHP Replication Loop:
<script type="text/javascript">
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player<?= $dAgenda['id'];?>', {
height: '230',
width: '454',
videoId: '<?= $dAgenda['link'];?>',
events: {}
});
}
function stopVideo() {
player.stopVideo();
}
</script>
Out of PHP Repeat Loop:
<script type="text/javascript">
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
</script>
Conclusion:
The video is only appearing for the last movie in the PHP loop!