W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2012

Re: connection ceremony for iframe postMessage communications

From: John J Barton <johnjbarton@johnjbarton.com>
Date: Thu, 9 Feb 2012 12:17:31 -0800
Message-ID: <CAFAtnWzPSOqWrk3mj9uGv4BGAebfzw8++XkyPStiDi=vN9dRVQ@mail.gmail.com>
To: Boris Zbarsky <bzbarsky@mit.edu>
Cc: public-webapps@w3.org
On Thu, Feb 9, 2012 at 11:49 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> On 2/9/12 1:15 PM, John J Barton wrote:
>>
>> This leads developers to look for events that will tell them about
>> 'load' on iframes, and that leads them to try
>> iframe.contentWindow.addEventListener(). It works fine for same-domain
>> iframes, but fails for cross-domain.
>
>
> Adding a load listener to the iframe element itself should work for this,
> no?

I guess you mean: by issuing
  iframe.addEventListener('load', handler, false);
you get notified when the iframe load event has completed (but you
don't need to touch the contentWindow property).

This will work if the iframe ensures that it completes its connection
work before 'load'. This prevents the iframe from using async loading
for the scripts that create the connection and for any code that
handles messages from the parent. Which, in a typical iframe
component, would be all the code, since its main job is to provide for
the parent.

In addition this solution requires that the above addEventListener be
attached after the iframe is inserted (so the iframe exists) but
before the parent's 'load' event (which is after the iframe load and
thus too late.

So I'd say it does not solve the original problem and it's hard to use
too. Other than that it's a fine idea ;-).

jjb
Received on Thursday, 9 February 2012 20:18:04 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:50 GMT