2014-06-05 76 views
1

我正在引导模态弹出播放YouTube视频,应该停止点击关闭或关闭外面。引导模式点击关闭或外部点击不会停止youTube视频

以下是我的代码。

<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-dialog"> 
    <div class="modal-content" style="width: 682px;"> 
     <div class="modal-header" style="border:none;"> 
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 

     </div> 
     <div class="modal-body"> 
     <iframe width="640" height="390" src="http://www.youtube.com/watch?v=8CdAfYwEGCI" frameborder="0" allowfullscreen></iframe> 
     </div> 
    </div> 
    </div> 
</div> 

我已经尝试了StackOverflow上类似问题的下面的脚本,但它们不起作用。

脚本:

$('.close').click(function() { 
    $('#myModal2').hide(); 
    $('#myModal2 iframe').attr("src", jQuery("#myModal2 iframe").attr("src")); 
}); 

类似的问题#1简称:

How to stop a Youtube Video Playing on Twitter Bootstrap Model Close

Start/stop youtube iframe when modal is shown/hidden through the api and Jquery events

..更

回答

0

引导有一个名为事件hidden.bs.modal

您可以将你的函数这一事件,而不是click

$('#myModal2').on('hidden.bs.modal', function(){ 
$('#myModal2').hide(); 
$('#myModal2 iframe').attr("src", jQuery("#myModal2 iframe").attr("src")); 
}); 

此外,自举应自动隐藏的关闭按钮的模式(这应该已经建成)

至于停止播放影片,它看起来像你的IFRAME SRC设置到其自身

(未苏再如果,将停止视频,如果是的话那么你可以在下面忽略我的意见,但如果没有,你可能要设置src为空)

$('#myModal2 iframe').attr("src", ""); 

这将肯定停止视频