在我的网站上,我正在尝试制作一个带有多个链接的 youtube 视频播放器,以便在点击时加载不同的视频。到目前为止,它适用于 IE 和 Firefox,但我无法让它在 Chrome 中运行。我没有收到任何 JS 错误,但是通过使用警报进行测试,我发现onYouTubePlayerReady
没有触发。这是我的代码:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2/swfobject.js"></script>
<a name="ytplayer"></a>
<div id="ytplayer_div">You need Flash player 8+ and JavaScript enabled to view this video.</div>
<script type="text/javascript">
swfobject.embedSWF(
'http://www.youtube.com/v/vlArwl2EoDc&enablejsapi=1&rel=0&fs=1&hd=1',
'ytplayer_div',
'720',
'400',
'11',
null,
null,
{
allowScriptAccess: 'always',
allowFullScreen: 'true'
},
{
id: 'ytplayer_object'
}
);
var myytplayer;
function onYouTubePlayerReady(playerId) {
myytplayer = document.getElementById("ytplayer_object");
}
function ytplayer_loadvideo( id ) {
if (myytplayer) {
myytplayer.loadVideoById(id);
}
}
</script>
<div>
<a href="#ytplayer" onClick="ytplayer_loadvideo( 'vlArwl2EoDc' );"><img src="http://img.youtube.com/vi/vlArwl2EoDc/default.jpg" /></a> <a href="#ytplayer" onClick="ytplayer_loadvideo( 'G4EIgIEngKY' );"><img src="http://img.youtube.com/vi/G4EIgIEngKY/default.jpg" /></a> <a href="#ytplayer" onClick="ytplayer_loadvideo( 'wxXnf_oCRI4' );"><img src="http://img.youtube.com/vi/wxXnf_oCRI4/default.jpg" /></a>
</div>
有谁知道发生了什么?