我有下面的代码,并希望打开页面加载模式。作为一个普通的onload功能没有工作,我点击的触发尝试过。但是,这也并不自动播放视频,而当我手动点击它的span
。
任何想法,为什么?
<div id="videoModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="videoModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-body">
<iframe frameborder="0" allowfullscreen id="video" class="video" src="" data-video="https://www.youtube.com/embed/kLKOO_-MYKg?modestbranding=0&rel=0&controls=0&showinfo=0&html5=1"></iframe>
<script>
$(document).ready(function() {
var videoSrc = $("#video").data('video');
$("#videoModal").on('hidden.bs.modal', function () {
$("#videoModal iframe").attr('src', '');
});
$("#videoModal").on('show.bs.modal', function () {
$("#video").attr("src", videoSrc+"&autoplay=1");
});
setTimeout(function(){
$("#launch").click(); // this does not auto play the video
}, 200);
});
</script>
</div>
</div>
</div>
</div>
<!-- manually clicking this will launch the modal and auto play the video -->
<span id="launch" data-toggle="modal" data-target="#videoModal">click</span>
找到了解决办法:只需添加allow="autoplay"
到IFRAME的伎俩