Re: connection ceremony for iframe postMessage communications

On Thu, 9 Feb 2012, John J Barton wrote:
> On Thu, Feb 9, 2012 at 4:42 PM, Ian Hickson <ian@hixie.ch> wrote:
> > On Thu, 9 Feb 2012, John J Barton wrote:
> >>
> >> However the solution has two significant problems:
> >>   1. There is no way to know if portToOtherWindow is connected before
> >> you issue postMessage()
> >
> > Just have the target message you when it's ready.

What I meant was just to do this on the receiving side (inside the 
iframe), after the onmessage handler has been set up (which we are 
assuming happens after the 'load' event for some reason):

   parent.postMessage('load', '*');

That way you don't have to depend on the 'load' event, you can just wait 
for the message from the inner frame. Then when you get it, you know you 
can start sending..

And when you do send, you just send a message whose contents are just a 
single key saying what API endpoint you want, and a port, which you then 
use for all communication for that particular API call.

No races or anything.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Friday, 10 February 2012 07:53:55 UTC