Javascript addEventListener onStateChange not working in IE

I have two colorbox popups that show YouTube videos. When they finish the game, I try to automatically close the colorbox window. This code below works fine in firefox, but in IE I can't get addEventListener to work. I tried attachEvent without success. Can anyone suggest any suggestions as to how to solve this? It seems simple, but I'm exhausted trying to find a solution. By the way, this is my first time in stackoverflow, and it is very impressive.

UPDATE 1:

Well, this is my current code. It works fine in FF, but IE only gives good results. IE8 debugger also doesn't report errors ...

function onYouTubePlayerReady(playerId) {
  if (playerId && playerId != 'undefined') {
    if(playerId && playerId == 'ytvideo1'){
      var ytswf = document.getElementById('ytplayer1');
      alert('good');
    } else if(playerId && playerId == 'ytvideo2'){
      var ytswf = document.getElementById('ytplayer2');
    } else {
    }

    setInterval('', 1000);
    ytswf.addEventListener('onStateChange', 'onytplayerStateChange');
    alert('great');
  }
}


function onytplayerStateChange(newState) {
  alert('amazing');
  if(newState == 0){
    $.fn.colorbox.close();
    alert('perfect');
  }
}

Update 3: Solution

onComplete colorbox swfobject , IE.

+5
3

IE ,

ytswf = document.getElementById('ytplayer1');

, swf, IE , div

function onYouTubePlayerReady(playerId) {
  ytswf = document.getElementById("ytplayer1");
  ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}

swfobject.embedSWF("http://www.youtube.com/v/SPWU-EiulRY?
hl=en_US&hd=0&rel=0&fs=1&autoplay=1&enablejsapi=1&playerapiid=ytvideo1",
"popupVideoContainer1", "853", "505", "8", null, null, params, atts);

, $(function()

var ytswf; <script>

+2

IE addEventListener does? attachEvent ?

if (el.addEventListener){   
    el.addEventListener('click', modifyText, false);    
else if (el.attachEvent){   
    el.attachEvent('onclick', modifyText);   
}
+4

YouTube addEventListener, AS3. :

player.addEventListener(: String, : String):

YouTube , , :

function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("myytplayer");
  ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}

function onytplayerStateChange(newState) {
   alert("Player new state: " + newState);
}

YouTube , , , , IE. .

, Google/YouTube:

function onYouTubePlayerReady(playerId) {
  if(playerId && playerId == 'ytvideo1'){
    var ytplayer = document.getElementById('ytplayer1');
  } else if(playerId && playerId == 'ytvideo2'){
    var ytplayer = document.getElementById("ytplayer2");
  } else {
    return;
  }

  ytplayer.addEventListener('onStateChange', 'onytplayerStateChange');
}

So it turns out that the error that occurs here is due to the confusion created with the name 'addEventListener' method. In the JavaScript implementation of W3C, the second parameter is a function during the implementation of YouTube, the second is a string. Give this snapshot =).

-1
source

All Articles