IE8/9 window.postMessage not working, but why?

The "postMessage" is an HTML5 API, it is available in all major browsers including IE8/9. What I am trying to do is to create a popup window from a page, and be able to talk to the popup window using "postMessage". This works in every browser except IE8/9. Disappointed!

It looks like IE8/9 only allows the communication between iframes, but not between two windows, even the windows are within the same hierarchy.

Answers


The .postMessage method works, you just need to understand how it works from IE8 and up. Unfortunately, for IE8 and IE9 it will not do what you're seeking (though it does in IE10). While you can send messages between frames in IE8/9, you cannot send messages to a separate window.

There is a work-around that works in some instances. Martin Beeby discusses it in the last paragraph of his blog post on the issue: PostMessage Popups and IE.

For more on this, and a few other caveats, see Eric Lawrence's post on MSDN.


I found that .postMessage() in IE9 was unreliable unless I used Strings.

My workaround was to simply call .postMessage(JSON.stringify({object: 'data'})) and use JSON.parse() in the onMessage() function on the other end.


Need Your Help

How do I open a script file in RStudio using an R command?

r rstudio

I have a simple script file called test.R. It's saved in the working directory. When I go to File > Open > test.R, it opens the file in the editor (without executing the code, which is what I...

Delphi won't run

delphi delphi-7

If I try to run Delphi 7, I get this frightening message: