joe*_*g P 3 javascript youtube iframe events
我尝试捕捉youtube iframe的事件:http: //lab.joergpfeiffer.de/videofull/youtube.php
所以我先打电话给api
<script type='text/javascript' src='http://www.youtube.com/player_api'></script>
Run Code Online (Sandbox Code Playgroud)
我设置了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>
Run Code Online (Sandbox Code Playgroud)
并尝试稍后设置事件
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'); }
Run Code Online (Sandbox Code Playgroud)
无论我做什么,都没有发生任何事件.我读了10次iframe api.它应该实际工作.
任何的想法?
小智 6
在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);
Run Code Online (Sandbox Code Playgroud)
如果stil有混淆,请访问http://code.google.com/apis/youtube/iframe_api_reference.html
归档时间: |
|
查看次数: |
12843 次 |
最近记录: |