Ejecute la función Javascript después del final del video de YouTube
Frecuentes
Visto 1,839 veces
3
I am loading up a youtube video through the youtube API, as I want to execute a line of jQuery when the video ends. For some reason my code will not execute, can someone point me in the right direction...
First I embed the iFrame
<iframe id="player" class="blo" width="219" height="207" src="http://www.youtube.com/embed/qNL81Khx_UE?enablejsapi" frameborder="0" allowfullscreen></iframe>
Then I create the API Script
<script type="text/javascript">
// 2. 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);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'qNL81Khx_UE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
</script>
Then I make a function
<script type="text/javascript">
var myPlayerState;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
alert('Something Happened');
}
myPlayerState = event.data;
}
if (myPlayerState == 1){
alert('Something Happened');
}
Can anyone let me know what I am doing wrong?
¡Gracias!
0 Respuestas
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas jquery youtube or haz tu propia pregunta.
I hope this useful stackoverflow.com/questions/10459622/… - Sakata Gintoki