2014-06-05 81 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", ""); 

這將肯定停止視頻