0
我试图跟踪我网站上的任何事件YouTube视频。 为什么这不起作用? HTML:YouTube API - addEventListener不工作
<div>
<iframe id="video-block" width="560" height="315" src="//www.youtube.com/embed/123456?enablejsapi=1 " frameborder="0" allowfullscreen ></iframe>
</div>
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);
function onYouTubeIframeAPIReady() {
alert("1");
ytplayer = new YT.Player('video-chia');
ytplayer.addEventListener('onStateChange', function(e) {
alert('State change');
});
}
我很好奇。什么状态的变化可以捕捉到这一点? Regards – loveNoHate 2014-09-21 08:49:13
哈哈,这段代码来自YouTube API的文档。您至少可以发布代码的来源... @DOCASAREL请参阅https://developers.google.com/youtube/iframe_api_reference?hl=fr部分:**入门** – mpgn 2014-09-21 10:36:59