W3C home > Mailing lists > Public > public-webapi@w3.org > January 2007

Re: capturing load events

From: Joćo Eiras <joao.eiras@gmail.com>
Date: Mon, 01 Jan 2007 23:20:04 -0000
To: Shadow2531 <shadow2531@gmail.com>
Cc: "Web APIs WG" <public-webapi@w3.org>
Message-ID: <op.tlh0fqcrjz3wb9@dragast>

Shadow2531 <shadow2531@gmail.com> escreveu:

> On 12/31/06, Joćo Eiras <joao.eiras@gmail.com> wrote:
>> > So, my question is, what's the reason for not wanting win t+b(2) to
>> fire?
>> The load event doesn't bubble, so it fires with the Document as
>> target, and doesn't go up. But compatibility with the current web
>> demands this.
> Thanks Joćo.
> O.K., so we're just saying that window.addEventListener("load", func,
> false) doesn't make sense, *technically*, because the document load
> doesn't bubble up to the window.
> So, it seems that:
> win cap (1) ([object HTMLImageElement])
> doc cap (1) ([object HTMLImageElement])
> win cap (1) ([object HTMLDocument])
> doc t+b (2) ([object HTMLDocument])
> win t+b (2) ([object HTMLDocument])
> is the way to go because it doesn't break the 'false' behavior and it
> allows 'true' to work as mosts sites intend. (Opera can produce that
> with the body -> document target fixes.)
> Assuming the 'true' +"load" behavior for window.addEventListener is
> solved, the the only problem is how to explain how
> window.addEventListener("load", func, false) can work if load doesn't
> bubble.

That's an exception, although not covered in any specification.
This rule will be part of the Window specification.

> So, since we still need  window.addEventListener("load", func, false)
> to work, can we just have the window spec say that in the case of
> "load" and 'false' for window.addEventListener,
> window.addEventListener("load", func, false) is just an alias to
> document.addEventListener("load", func, false)?
> That appears to be what Opera does anyway (or close to it)
> window.addEventListener("load", function() {
> alert(this);
> }, false);
> 'this' is HTMLDocument in Opera. In FF it's 'window'.

Note that the specification doesn't make any claim related to this. It's  
implementation defined.
The proper way to get that reference is using currentTarget.
Making an alias between window.addEventListener("load", func, false) and  
document.addEventListener("load", func, false) only contributes to making  
the spec more ambiguous.
The behaviour is quite simple: when the event is load and the target the  
document, fire load listeners in the document's view, if there are any.

> And with:
> function test() {
> alert("test");
> }
> window.addEventListener("load", test, false);
> document.removeEventListener("load", test, false);
> you won't see an alert in Opera.

That's a bug in Opera (see 168168), which window event listeners are  
registered to the document.
Received on Monday, 1 January 2007 23:20:14 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:16:22 UTC