W3C home > Mailing lists > Public > whatwg@whatwg.org > January 2010

[whatwg] using postMessage() to send to a newly-created window

From: Drew Wilson <atwilson@google.com>
Date: Tue, 5 Jan 2010 15:04:49 -0800
Message-ID: <f965ae411001051504s2f3abdc1y13f8c4da3303d4f7@mail.gmail.com>
I ran into this early last year when I was first investigating MessagePorts:

http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-March/018893.html

I dimly recall that the response I got off-list (via IRC?) was that this was
expected behavior (the intended use for window.postMessage() is for
communicating with child iframes, where you can register an onload handler
to be notified when it's safe to post messages), but I agree that it would
be worthwhile to explicitly state this somewhere in the spec.

-atw

On Mon, Dec 21, 2009 at 7:24 PM, Dirk Pranke <dpranke at chromium.org> wrote:

> Hi all,
>
> In the course of testing something today, I attempted to create a
> window and immediately post a message to it, and was surprised that it
> didn't seem to work.
>
> E.g.:
>
> var w = window.open("http://x");
> w.postMessage("hello, world", "*");
>
> w never got the message - this seemed to be consistent across Safari,
> Chrome, and FF (all I had installed on my Mac at the time, so
> apologies to Opera, IE, and anyone else I've left out).
>
> Is this supposed to work? If not, is there a reliable way for the the
> source to know when it is safe to send a message to the target? The
> only way I can think of is for the target to send a message back to
> the source, which only works if the target can get a reference to the
> source using window.opener, which may or may not be possible or
> desirable ...
>
> If this isn't supposed to work, can we state this explicitly in the spec?
>
> -- dirk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20100105/354eec99/attachment.htm>
Received on Tuesday, 5 January 2010 15:04:49 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:20 UTC