Ventana AddEventLinstener devuelve Objeto de llamada no válido en IE

I have this snippet of code in the parent html which contains an iframe child that will send window.postmessage. Its a child to parent postmessage.

// Create IE + others compatible event handler
var eventMethod = iFrame.addEventListener ? "addEventListener" : "attachEvent";
var eventer = iFrame[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

eventer(messageEvent,function(e) {   // THIS ERRORS
  console.log('parent received message!:  ',;

It works in firefox and chrome, but not in IE. The eventer... line causes a Invalid calling Object message in IE. Can I actually do the above code in IE?

Please note: iFrame[eventMethod] instead of window[eventMethod] in code.

preguntado el 12 de febrero de 14 a las 08:02

In what version of IE ? -

Seems like if I use window instead of iFrame it does the same thing. Partially solved although I'd like to know why. -

1 Respuestas

All messages are routed to the window object. If you have more than one iFrame and you need to know which one the message came from then you need to include that in your message.

As the iFrame has no way of knowing the ID of the iFrame it is in, you have to have the parent past this into the iFrame and it can then uses this in it's responses.

Respondido 05 Abr '14, 21:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.