Firefox在MODAL窗口关闭后继续播放音频-如何解决?

时间:2018-08-21 14:15:55

标签: javascript html twitter-bootstrap bootstrap-modal

在chrome上可以正常工作,但是在Firefox上,只要弹出窗口关闭,音频就会在后台继续播放。

有人可以帮助解决此问题吗? 10倍 乌迪

var mobileDetect = new MobileDetect(window.navigator.userAgent);

$(document).ready(function(){
  $("#myModal").on("hidden.bs.modal",function(){
     $("#iframeYoutube").attr("src","#");
  })
})

function changeVideo(vId){
   var iframe=document.getElementById("iframeYoutube");
  iframe.src="https://www.youtube.com/embed/"+vId+"?autoplay=1&modestbranding=1&rel=0&showinfo=0";

if (mobileDetect.mobile()) {
    window.location = "https://www.youtube.com/watch?v=" + vId;
return;
  }

   $("#myModal").modal("show");
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">

 <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><a href="#"><span aria-

hidden="true" style="color:white">&times;</span></a></button>
      </div>
      <div class="modal-body">
      
        <iframe id="iframeYoutube" width="700" height="394" src="https://www.youtube.com/embed/e80BbX05D7Y" 

frameborder="0" allowfullscreen></iframe> 

1 个答案:

答案 0 :(得分:0)

这应该可以解决您的问题,似乎有些棘手,但是在关闭模态后,视频肯定会被重新加载:

$("#myModal").on('hidden.bs.modal', function (e) {
  $("#myModal #iframeYoutube").attr("src", $("#myModal #iframeYoutube").attr("src"));
});