title: youtube api does not fire ENDED event when video ends (using iframe)
body: <p>I'm trying to catch an event so that when a youtube player ends, I can then redirect to another web page.  but it does not work.  Can anyone spot anything wrong?  The javascript does seem to compile OK.</p>
  
  <p>Here's the code of the entire page (I actually pasted it from the view-source page of the browser below.<br>
      Its fairly simple, the event is listed in the onYouTubePlayerAPIReady() function and I assume it should fire when the code ends.  I've put in 'alert' to see if it does.  It looks like it does not:</p>
  
  <pre><code>    &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;  
          $(document).ready(function () {
              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 &lt;iframe&gt; (and YouTube player)
       //    after the API code downloads.
       function onYouTubePlayerAPIReady() {
           player = new YT.Player('iframeid', {
               events: {   
                   'onReady': onPlayerReady,          
                   'onStateChange': onPlayerStateChange
               }
           });
       }
  
       function onPlayerReady(event) {
  
       }
       function onPlayerStateChange(event) {
  
           if (event.data == YT.PlayerState.ENDED) {
               alert("video is over");
               location.href= 'k_Origins.aspx';
           }
           else if (event.data == YT.PlayerState.PAUSED) {
  
           }
           else if (event.data == YT.PlayerState.PLAYING) {
  
           }
           else if (event.data == YT.PlayerState.BUFFERING) {
  
           }
           else if (event.data == YT.PlayerState.CUED) {
  
           }
           else {
  
           }
  
       }
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form method="post" action="dostuff.aspx" id="form1"&gt;
  
  &lt;div id="ContainPlayer"&gt;
  
      &lt;iframe id="iframeid" width="420" height="315"
      src="http://www.youtube.com/embed/8X0ZkN_EtTE?hl=en&amp;fs=1&amp;autoplay=1&amp;autohide=0&amp;enablejsapi=1&amp;modestbranding=1&amp;playerapiid=ourvideoid&amp;rel=0" 
      frameborder="0" &gt;&lt;/iframe&gt;
      &lt;/div&gt;
  
      &lt;/div&gt;
  
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>