I ran into this early last year when I was first investigating MessagePorts:<div><br></div><div><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-March/018893.html">http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-March/018893.html</a></div>
<div><br></div><div>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.</div>
<div><br></div><div>-atw<br><br><div class="gmail_quote">On Mon, Dec 21, 2009 at 7:24 PM, Dirk Pranke <span dir="ltr"><<a href="mailto:dpranke@chromium.org" target="_blank">dpranke@chromium.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
In the course of testing something today, I attempted to create a<br>
window and immediately post a message to it, and was surprised that it<br>
didn't seem to work.<br>
<br>
E.g.:<br>
<br>
var w = window.open("<a href="http://x" target="_blank">http://x</a>");<br>
w.postMessage("hello, world", "*");<br>
<br>
w never got the message - this seemed to be consistent across Safari,<br>
Chrome, and FF (all I had installed on my Mac at the time, so<br>
apologies to Opera, IE, and anyone else I've left out).<br>
<br>
Is this supposed to work? If not, is there a reliable way for the the<br>
source to know when it is safe to send a message to the target? The<br>
only way I can think of is for the target to send a message back to<br>
the source, which only works if the target can get a reference to the<br>
source using window.opener, which may or may not be possible or<br>
desirable ...<br>
<br>
If this isn't supposed to work, can we state this explicitly in the spec?<br>
<font color="#888888"><br>
-- dirk<br>
</font></blockquote></div><br>
</div>