已经嵌入的iframe无法与youtube api一起使用 [英] Already embedded iframe not working with the youtube api
本文介绍了已经嵌入的iframe无法与youtube api一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的iframe html
My iframe html
<iframe id="player" frameborder="0" width="660" height="371" allowfullscreen="" src="https://www.youtube.com/embed/CMm6tDavSXg?feature=oembed">
我的youtube js
My youtube js
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
event.target.playVideo();
}
但是仍然无法开始播放或其他任何内容...这里的问题在哪里?谢谢
But still it does not start playing or anything else... Where is the issue here? Thank you
推荐答案
- onPlayerReady不会在本地主机上触发就绪检查.
- 此外,在链接youtube.js文件时,它也必须位于iframe之后.
- 添加?enablejsapi = 1
- 有时在player_api和iframe_api中进行双重链接也会有所帮助
- //<在www.之前不是https://
- 摆放是关键.
问题在于您还需要向视频添加?enablejsapi = 1嵌入链接.
the problem is with the fact that you also need to add ?enablejsapi=1 to the video embed link.
//www.youtube.com/embed/F4efZDqXZKA?enablejsapi=1
小提琴: http://jsfiddle.net/y89je0k8/
那将解决您的问题.
这篇关于已经嵌入的iframe无法与youtube api一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文