- From: David Bruant <bruant.d@gmail.com>
- Date: Fri, 23 Dec 2011 19:40:49 +0100
- To: olli@pettay.fi
- CC: www-dom@w3.org, Boris Zbarsky <bzbarsky@MIT.EDU>
Le 23/12/2011 19:32, Olli Pettay a écrit :
> On 12/23/2011 08:13 PM, David Bruant wrote:
>> Hi,
>>
>> A couple of tweets and a private e-mail conversation with Boris Zbarsky
>> led to the conclusion that some event handlers can't be expressed with
>> event.addEventListener
> you mean eventtarget.addEventListener ;)
Of course :-)
>> and require inline on* attributes. I'd like to
>> raise this concern here.
>>
>> Currently, if one wants to know when an iframe was loaded, she has to
>> set an inline @onload attribute:<iframe onload="doSomething()">
>> Several aspects contribute to the necessity of this attribute. First,
>> the event has to be fired synchronously. Second, this happens while HTML
>> parsing is ongoing, so the HTMLIframeElement is created while parsing.
>> These two combined make that the event may need to be fired before any
>> script has the opportunity to use the HTMLIframeElement reference can be
>> attached a 'load' event listener.
>
> You can just add capturing event listener before <iframe> is added to
> document. For example
>
> <html>
> <head>
> <script>
> document.addEventListener("load",
> function(e) {
> if (e.target == document.getElementById("ifr");) {
> ...
> }
> },
> true
> );
> </script>
> </head>
> <body>
> <iframe id="ifd" src="http://www.foobar.html"></iframe>
> </body>
> </html>
.... yeah ... right ... *feeling embarrassed* :-s
Boris mentionned that the usual case is to want different listeners for
different iframes, but it can be implemented with your method or some
library on top of it.
Thanks :-)
David
Received on Saturday, 24 December 2011 08:41:50 UTC