Javascript 视频结束时youtube api调用函数
我需要知道嵌入的youtube视频何时通过javascript结束 这是我的嵌入代码:Javascript 视频结束时youtube api调用函数,javascript,youtube-api,youtube-javascript-api,Javascript,Youtube Api,Youtube Javascript Api,我需要知道嵌入的youtube视频何时通过javascript结束 这是我的嵌入代码: <object id="ytplayer" height="35" width="560"><param name="movie" value="http://www.youtube.com/v/u8C-ZTQJIkU?version=3&enablejsapi=1&playerapiid=ytplayer&rel=0&fs=0&theme=l
<object id="ytplayer" height="35" width="560"><param name="movie" value="http://www.youtube.com/v/u8C-ZTQJIkU?version=3&enablejsapi=1&playerapiid=ytplayer&rel=0&fs=0&theme=light&showinfo=0&modestbranding=1&autohide=0&color=white">
</param>
<param name="allowFullScreen" value="false">
</param>
<param name="allowscriptaccess" value="always">
</param>
<embed src="http://www.youtube.com/v/u8C-ZTQJIkU?version=3&rel=0&fs=0&theme=light&showinfo=0&modestbranding=1&autohide=0&color=white" type="application/x-shockwave-flash" allowfullscreen="false" width="560" height="35" allowscriptaccess="always"></embed></object>
这是我到目前为止发现它何时结束的代码,但警报没有出现。你能帮我找出哪里不对劲吗
<script type="text/javascript" src="http://www.youtube.com/player_api"></script>
<script type="text/javascript">
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("ytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}
function onytplayerStateChange(newState) {
alert("Player's new state: " + newState);
}
</script>
函数onYouTubePlayerReady(playerId){
ytplayer=document.getElementById(“ytplayer”);
ytplayer.addEventListener(“onStateChange”、“onytplayerStateChange”);
}
函数onytplayerStateChange(newState){
警报(“玩家的新状态:+newState”);
}
谢谢。您似乎只显示了部分代码。对象标记应包含名为id的属性,该属性应设置为ytplayer。以下是完整的工作代码:
<object type="application/x-shockwave-flash" id="ytplayer" data="http://www.youtube.com/v/u8C-ZTQJIkU?enablejsapi=1&playerapiid=ytplayer&version=3" width="425" height="356"><param name="allowScriptAccess" value="always">
<param name="allowScriptAccess" value="always">
</object>
</body>
</html>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js"></script>
<script type="text/javascript">
function onYouTubePlayerReady(playerId) {
var player = document.getElementById("ytplayer");
player.addEventListener("onStateChange", "onytplayerStateChange");
}
function onytplayerStateChange(newState) {
alert("New state " + newState);
}
</script>
函数onYouTubePlayerReady(playerId){
var player=document.getElementById(“ytplayer”);
player.addEventListener(“onStateChange”、“onytplayerStateChange”);
}
函数onytplayerStateChange(newState){
警报(“新状态”+新状态);
}
您的代码可以工作,但我的嵌入代码与您使用的不同,我的代码无法工作。很抱歉,您的代码无法工作。建议不要选择使用嵌入的方法。请参阅:另外,请考虑使用IFRAMAPI: