2013-03-09 67 views
2

我使用引導模式彈出顯示音頻/視頻附加在項目中。 點擊取消按鈕時,模式應該關閉,音頻應該停止播放。 這是在Chrome中正常工作,但在Mozilla和IE中,我點擊取消模式解散,但aduio /視頻繼續播放。引導模式的數據關閉關閉模式不關閉音頻在mozila和IE

這是模式彈出的HAML代碼:

%a{ href: "#", class: "x", title: "Close", :'data-dismiss' => "modal" } 
    .diagRepeater   

    = swf_tag "StrobeMediaPlayback", 
     :width => '620', 
     :height => (attachment.media_content_type.split('/')[0] == 'audio' ? '65' : '340'), 
     :flashvars => { :urlIncludesFMSApplicationInstance => "true", 
     :src => URI.encode("#{request.protocol}#{request.host_with_port}" + attachment.media.url), 
     :playButtonOverlay => (attachment.media_content_type.split('/')[0] == 'audio' ? 'false' : 'true'), 
     :controlBarAutoHide => (attachment.media_content_type.split('/')[0] == 'audio' ? 'false' : 'true') }, 
     :parameters => { :allowFullScreen => "true", :wmode => "direct",  :allowScriptAccess => "always" } 

這是bootstrap.js文件中的代碼:

hide: function (e) { 
e && e.preventDefault() 

    var that = this 
    alert(this.toString()); 
    e = $.Event('hide') 

    this.$element.trigger(e) 

    if (!this.isShown || e.isDefaultPrevented()) return 

    this.isShown = false 

    $('body').removeClass('modal-open') 

    escape.call(this) 

    this.$element.removeClass('in') 

    $.support.transition && this.$element.hasClass('fade') ? 
     hideWithTransition.call(this) : 
     hideModal.call(this) 
    } 
+0

當您關閉模式時,您可以對視頻調用動作來停止播放。 – kobaltz 2013-03-09 04:32:07

+0

如何做到這一點,你可以請解釋一下 – User16119012 2013-03-09 05:05:16

回答

3

有一個簡單的方法,如果您有任何麻煩只需使用下面的代碼和模式首先明確HTML,再次把它和它應該工作,每次:

$('.x').live('click',function(){ 
    var media_html = ''; 
    $('.modalBox').each(function(){ 
     media_html = $(this).html(); 
     $(this).html(''); 
     $(this).html(media_html); 
    }); 
}); 
1

嘗試是這樣的:

$('.x').click(function(){ 
    var myAudio = document.getElementsByTagName("audio")[0]; 
    if(myAudio != undefined){ 
     myAudio.StopPlay(); 
    } 
} 
+0

嘿斯科特,感謝您的快速回答,但它並沒有爲我工作。它給出錯誤,stopPlay()不是函數。 – User16119012 2013-03-09 09:59:00

+0

我試過stopAudio(),stopVideo()沒人在工作 – User16119012 2013-03-09 10:29:51

0
<a href="#" class="mydemo">Open Video</a> 
<div id="myModal" class="modal hide" aria-hidden="true"> 
    <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
    </div> 
    <div class="modal-body"> <iframe width="470" height="310" frameborder="0" allowfullscreen=""></iframe></div> 
    <div class="modal-footer"> 
     <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> 
    </div> 
</div> 

<script type="text/javascript"> 
$('.mydemo').click(function() { 
      var src = 

'http://www.youtube.com/v/2EnI9K8Fkf4&amp;rel=0&amp;autohide=1&amp;showinfo=0&amp;autoplay=1'; 
      $('#myModal').modal('show'); 
      $('#myModal iframe').attr('src', src); 
      }); 

     $('#myModal.modal').bind('hide', function() { 
      var iframe = $(this).children('div.modal-body').find('iframe'); 
      var src = iframe.attr('src'); 
      iframe.attr('src', ''); 
      iframe.attr('src', src); 
      }); 

</script> 

此代碼適用於IE。