使用YouTube的JavaScript API来控制iFrame嵌入。我已经设置了函数,没有看到任何错误...但是我没有记录here记录API的初始化。
是的,它是在服务器而不是本地服务器上运行的:http://jp.redwoodmatthews.com
我想念什么吗?下面的HTML和JavaScript!谢谢你的帮助。
iFrame HTML:
<iframe id="ryanBingham" src="http://www.youtube.com/v/Xz5SNppHRxc?rel=0?enablejsapi=1&version=3&playerapiid=video" frameborder="0"></iframe>
JavaScript:
function onYouTubePlayerReady(playerId) {
video = document.getElementById('ryanBingham');
video.addEventListener('onStateChange', 'onytplayerStateChange');
console.log('YouTube API initiated');
}
最佳答案
您使用了错误的API文档。这适用于iframe:https://developers.google.com/youtube/iframe_api_reference
由于原产地限制,它的工作方式略有不同。另外,ready函数名为onYouTubeIframeAPIReady
。
最后但并非最不重要的一点,请确保您load the API JS file
关于javascript - Youtube JavaScript API未初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12342858/