W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2006

Re: capturing load events

From: Master Br <master@sitesbr.net>
Date: Thu, 28 Dec 2006 10:11:34 -0300
Message-ID: <4593C286.50602@sitesbr.net>
To: Joćo Eiras <joao.eiras@gmail.com>
CC: "Hallvord R. M. Steen" <hallvord@opera.com>, "www-dom@w3.org" <www-dom@w3.org>
I have one opinion:

The correct behaviour for the load event in the 
*window.addEventListener, is to run ONLY ONCE, as Gecko does*, because:

Let's review some javascript:

When you use an object + dot + function it means that this function will 
be working for ONLY THAT object.

*It adds an Event Listener to the Window Object. The document is the 
interactive part of the window, so when the document is loaded, it MAKES 
SENSE that it will fire an event to the window = THIS IS THE CORRECT 

See this other object and function:
*NOW I put an Event Listener on the IMAGE object. This function will 
work on the first image in the document.

So, *window.addEventListener( 'load', function(){ alert('Only the body 
load event must be caught here, as this function belongs to the WINDOW 
object and not to its children')}, true)* comparing those browsers:

Gecko fires the function only when the document is completely loaded. 
This is the right behavior, as the event was put on the WINDOW object,  
NOT TO EVERY children elements of it.

Opera fires the function for every load event of any childNode. That is 
INCORRECT. The event observer was put on the WINDOW object, not to every 
image, or other "sub children".

Run this little test and see:

Firefox says:
-First Image was loaded
-Second Image was loaded
-Body was loaded

Opera says
-Body was loaded
-Body was loaded
-Body was loaded

Best Regards

> I too have 3 questions:
>   - is the window considered as a target in the entire event capturing 
> and bubbling phases ?
>     * in Gecko yes, in Opera no.
>   - should events registered to the window have the document as target ?
>     * both in Gecko and Opera yes.
>   - should capturing of load events be supported too when registering 
> a capturing event listener in the window ?
>     * in Opera yes, in Gecko no as consequence of their 'fix'
> The ecmascript binding needs clarification in this regard.
> Hallvord R. M. Steen <hallvord@opera.com> escreveu:
>> Hi,
>> I have a request for clarification regarding the behaviour of 
>> capturing events.
>> Opera has implemented capture of load events in the document, meaning 
>> that an event listener added with
>> window.addEventListener('load', func, true);
>> would run for every load event on IMG, SCRIPT, LINK rel="stylesheet" 
>> etc. in the document.
>> This is also implemented in Safari but not supported in Mozilla until 
>> recently (see bug 331306 - [1])
>> While we think Opera's/Safari's implementation is correct according 
>> to the spec, a number of sites out there rely on Mozilla's bug and 
>> expect such an event listener to run only once.
>> Mozilla developers have proposed a solution in bug 335251 [2]. They 
>> suggest that load events should not propagate to the "window" object 
>> in the browser's JavaScript environment.
>> Pros of Mozilla's suggestion:
>>   - it's backwards compatible with existing content
>> Cons:
>> - we introduce an inconsistency to the whole event listener model 
>> that means for example these two will mean very different things..
>> window.addEventListener('click', func, true); // runs for any click 
>> event
>> window.addEventListener('load', func, true); // runs once only
>> It is not clear from the DOM Events spec how the "window" object fits 
>> into the capturing/bubbling. Could this be clarified? Which behaviour 
>> should be considered correct per the spec?
>> [1] https://bugzilla.mozilla.org/show_bug.cgi?id=331306
>> [2] https://bugzilla.mozilla.org/show_bug.cgi?id=335251
>> Commentary:
>> http://my.opera.com/hallvors/blog/2006/12/23/firechicken
Received on Thursday, 28 December 2006 12:20:36 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:13 UTC