Note that there are some explanatory texts on larger screens.

plurals
  1. POYoutube Javascript API: not working in IE
    primarykey
    data
    text
    <p>I have an embedded Youtube video, and I want to capture events when the user pauses the video, skips around, etc. Following the examples at Google's documentation (<a href="http://developers.google.com/youtube/js_api_reference" rel="nofollow noreferrer">http://developers.google.com/youtube/js_api_reference</a>), I do the following:</p> <pre><code>var video = (my video ID here); var params = { allowScriptAccess: "always" }; var atts = { id: "youtubeplayer" }; var x = 854; var y = 480; swfobject.embedSWF("http://www.youtube.com/v/" + video + "?enablejsapi=1&amp;playerapiid=ytplayer&amp;version=3", "bobina", x, y, "8", null, null, params, atts); function onYouTubePlayerReady(playerId) { youtubeplayer = document.getElementById('youtubeplayer'); youtubeplayer.addEventListener("onStateChange", "onytplayerStateChange"); youtubeplayer.setPlaybackQuality('large'); } function onytplayerStateChange(newState) { //Make it autoplay on page load if (newState == -1) { youtubeplayer.playVideo(); } var tiempo=youtubeplayer.getCurrentTime(); //Rounds to 2 decimals var tiempo = Math.round(tiempo*100)/100; alert(tiempo); } </code></pre> <p>Now, all this works perfectly in Firefox and Safari, but there's no way to make it work in IE8 (by which I mean: the video loads, but events aren't captured: the event handler never gets called). According to <a href="https://stackoverflow.com/questions/2885500/javascript-addeventlistener-onstatechange-not-working-in-ie">javascript addEventListener onStateChange not working in IE</a> , IE doesn't support addEventListener(), so I tried replacing that line with:</p> <pre><code>youtubeplayer.attachEvent("onStateChange", onytplayerStateChange); </code></pre> <p>But it doesn't work either. (The author of that question says that he finally solved it by putting "onComplete in my colorbox and put the swfobject in that", but I'm not using a colorbox here (I don't even know what that is), so I don't understand what he means.</p> <p>Using alerts() to debug, I see that the first function (onYoutubePlayerReady()) is indeed called, but I can't even tell whether the event listener isn't being registered or whether it's the getElementById() that isn't working; I tried debugging by adding a:</p> <pre><code>alert(typeof youtubeplayer); </code></pre> <p>Right after it, but it doesn't even pop up.</p> <p>Oh, and one more thing: the video starts automatically in Firefox and Safari, but in IE it doesn't either. (And yes, I'm running this on a server, not on a local page).</p> <p>Anyone has any ideas? I don't really know what else to try.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload