如何使用 postMessage 聚焦 YouTube iframe 的控件
How to focus the controls of a YouTube iframe with postMessage
我在这方面有点不知所措。
目标是在页面加载时能够达到 spacebar
play/pause 和 f
全屏。
我正在这样加载 YouTube 嵌入:
<script src="https://www.youtube.com/iframe_api"></script>
<iframe
id="player"
frameborder="0"
allowfullscreen="1"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
width="1280"
height="720"
src="https://www.youtube.com/embed/<?php echo $video_id; ?>?autoplay=1&modestbranding=1&iv_load_policy=3&enablejsapi=1">
</iframe>
问题是,我可以使用 postMessage
聚焦 iframe 控件吗?或者其他方法?
如果是这样,我需要关注 iframe 中的哪个元素才能完成它?我认为是 html5-video-container > video
.
我认为我什至不需要 YouTube jsapi,但它现在就在那里。
我已经讨论过这个 SO question 大约十几次了,还有很多次。
您不能这样做,因为您无法将 postMessage
所需的 javascript 插入到 youtube 的 iframe 中。
是的,我看到您自己在页面上创建了 iframe,但它不是这样工作的。
我在这方面有点不知所措。
目标是在页面加载时能够达到 spacebar
play/pause 和 f
全屏。
我正在这样加载 YouTube 嵌入:
<script src="https://www.youtube.com/iframe_api"></script>
<iframe
id="player"
frameborder="0"
allowfullscreen="1"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
width="1280"
height="720"
src="https://www.youtube.com/embed/<?php echo $video_id; ?>?autoplay=1&modestbranding=1&iv_load_policy=3&enablejsapi=1">
</iframe>
问题是,我可以使用 postMessage
聚焦 iframe 控件吗?或者其他方法?
如果是这样,我需要关注 iframe 中的哪个元素才能完成它?我认为是 html5-video-container > video
.
我认为我什至不需要 YouTube jsapi,但它现在就在那里。
我已经讨论过这个 SO question 大约十几次了,还有很多次。
您不能这样做,因为您无法将 postMessage
所需的 javascript 插入到 youtube 的 iframe 中。
是的,我看到您自己在页面上创建了 iframe,但它不是这样工作的。