capturing load events

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

-- 
Hallvord R. M. Steen
Core QA JavaScript tester, Opera Software
http://www.opera.com/
Opera - simply the best Internet experience

Received on Wednesday, 27 December 2006 23:59:53 UTC