YouTube iframe 事件

2023-11-30

我尝试捕获 YouTube iframe 的事件:http://lab.joergpfeiffer.de/videofull/youtube.php

所以我首先调用api

<script type='text/javascript' src='http://www.youtube.com/player_api'></script>

我设置了 iframe

<iframe id="ytfullplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/p/B93C3D017CB2D65A?enablejsapi=1&origin=lab.domain.de" frameborder="0" ></iframe>

并尝试稍后设置事件

var ytfullplayer;
    function onYouTubePlayerAPIReady() {
        console.log('onYouTubePlayerAPIReady');
        ytfullplayer = new YT.Player('ytfullplayer', {
            events: {
              'onReady': testfunc,
              'onPlaybackQualityChange': testfunc,
              'onStateChange': testfunc,
              'onError': testfunc
            }
        });

    }
    function testfunc(){ alert('hello'); }

无论我做什么,都不会触发任何事件。我阅读了 iframe api 10 次。它实际上应该有效。

任何想法?


在 onYouTubePlayerAPIReady() 之前执行这些例程

// This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

如果仍然有困惑,请访问http://code.google.com/apis/youtube/iframe_api_reference.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

YouTube iframe 事件 的相关文章

随机推荐