我正在使用 iframe
嵌入来自 S3 的 mp4 视频。
<iframe class="you1" src="https://s3-us-west-2.amazonaws.com/vidcuratorfx2training/Video+1.mp4"></iframe>
但是该视频在加载时会自动播放。由于页面上有多个视频,因此所有视频都会自动开始播放。
我尝试使用下面的 js 代码暂停所有视频,但它不起作用。
<script>
window.onload = function() {
var frames = document.getElementsByTagName("iframe");
for (var i = 0; i< frames.length; i++) {
var innerDoc = (frames.item(i).contentDocument) ?
frames.item(i).contentDocument : frames.item(i).contentWindow.document;
var iframeVideoTags = innerDoc.getElementsByTagName("video");
for (var j = 0; j < iframeVideoTags.length; j++) {
iframeVideoTags.item(j).pause();
}
}
}
</script>
我的 CSS 限制仅限于使用 HTML5 视频标签。我只需要使用 iframe。
如何加载默认暂停的 iframe 视频?
最佳答案
看看这个
<video width="400" controls>
<source src="mov_bbb.mp4" type="video/mp4">
<source src="mov_bbb.ogg" type="video/ogg">
Your browser does not support HTML5 video.
</video>
But using above code, you need to add two different format of video for different browser support.
我最好的建议是将您的视频上传到 YouTube 并将 YouTube 链接添加到您的“iFrame's src”。使用 youtube url 的优点是 youtube 可以处理所有可能性,例如最小化屏幕等
关于javascript - 暂停 iframe src 中的所有视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52090618/