【问题标题】:Trying to use a embedded youTube link for auto play in custom HTML尝试使用嵌入式 YouTube 链接在自定义 HTML 中自动播放
【发布时间】:2021-03-16 13:48:42
【问题描述】:
我正在尝试实现一个指向自定义 Html 页面的嵌入式 YouTube 链接并将其设置为自动播放,但是当我打开我的主页时视频无法播放,只有在点击时才会播放。
<iframe width="1560" height="415" src="https://www.youtube.com/../?autoplay=1"
frameborder="0" allowfullscreen></iframe>
我想让它响应。
【问题讨论】:
标签:
javascript
html
shopify
【解决方案1】:
我不确定这是否有帮助甚至是否有效,但您是否尝试过类似的方法?
$(document).ready(function() {
$(iframe).click();
});
【解决方案2】:
你说https://www.youtube.com/../?autoplay=1
去掉问号前的斜线
我认为应该改为https://www.youtube.com/viddata?autoplay=1。
也许这就是它不播放的原因
【解决方案3】:
像 Coder2195 所说的那样去掉 URL 中的斜杠 (https://www.youtube.com/viddata?autoplay=1)。也尝试将此脚本添加到 HTML 文件中:
<script>
window.onload = function() {
var videoElement = document.getElementById("videoElement");
videoElement.click()
}
</script>
并使 iframe 元素具有自定义 id:
<iframe id="videoElement" width="1560" height="415" src="https://www.youtube.com/../?autoplay=1" frameborder="0" allowfullscreen></iframe>