I am using to open a you tube video in jQuery Model Window.In IE, Safari, Chrome When we close the overlay the YouTube video doesn't stop there but keeps playing in background and then create issues with other video.
My sample Code is
<div id="boxes">
<div class="window" id="dialog" style="top: 11px; left: 323.5px; display: block;">
<div align="right" class="clsbtn"><a class="close" href="#">Close</a></div>
<div>
<object width="580" height="360">
<param name="movie" value="http://www.youtube.com/v/eiz2vkSwSeQ&hl=en_US&fs=1&border=1"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/eiz2vkSwSeQ&hl=en_US&fs=1&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="580" height="360"></embed>
</object>
</div>
</div>
<div class="window" id="dialog" style="top: 11px; left: 323.5px; display: block;"></div>
</div>
<script>
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
开发者_开发知识库 $('#mask').hide();
$('#mask').css("opacity",0);
$('.window').hide();
});
$('#mask').click(function () {
$('#mask').css("opacity",0);
$(this).hide();
$('.window').hide();
});
</script>
When I click the thumbnail image the overlay will open and the respective video will play automatically. But I don't know how to stop the the video when we close the overlay.
$('.window').find('embed').stopVideo();
Or you can link to it directly:
$('#myPlayer').stopVideo();
Keep the object
into a js variable.
Then when you open modal, add it using html(nameOfObjectVar)
and when someone close the modal, you remove()
it.
That's what I did in a website that had a video in a modal.
Better than trying to use YT stopVideo()
which who knows when Google might change that.
精彩评论