Re: capturing load events

* Shadow2531 wrote:
>[...]

Try this fragment:

  <pre id='r'>&#xa;</pre>
  <script>
  function trace(s)
    {document.getElementById('r').firstChild.nodeValue+=s+"\n";}
  window.addEventListener('load',function(e){
    trace("win cap ("+e.eventPhase+") ("+e.target+")")}, true);
  document.addEventListener('load',function(e){
    trace("doc cap ("+e.eventPhase+") ("+e.target+")")}, true);
  document.addEventListener('load',function(e){
    trace("doc t+b ("+e.eventPhase+") ("+e.target+")")}, false);
  window.addEventListener('load',function(e){
    trace("win t+b ("+e.eventPhase+") ("+e.target+")")}, false);
  </script>
  <p><img alt='' src='http://www.w3.org/Icons/valid-xhtml10' /></p>

If you simply consider the window to be a parent of the Document, that
the load event does not bubble, and the load event is dispatched to the
img element first, then to the document, the correct result would be:

  win cap (1) ([object HTMLImageElement])
  doc cap (1) ([object HTMLImageElement])
  win cap (1) ([object HTMLDocument])
  doc t+b (2) ([object HTMLDocument])

I get the following: in Firefox/1.5.0.7:

  win cap (2) ([object HTMLDocument])
  win t+b (2) ([object HTMLDocument])

In Gecko/20060616 Minefield/3.0a1:

  win cap (1) ([object HTMLImageElement])
  doc cap (1) ([object HTMLImageElement])
  win cap (1) ([object HTMLDocument])
  win t+b (1) ([object HTMLDocument])

In Gecko/20061229 Minefield/3.0a2pre

  doc cap (1) ([object HTMLImageElement])
  win cap (2) ([object HTMLDocument])
  win t+b (2) ([object HTMLDocument])

In Opera 9:

  win cap (1) ([object HTMLImageElement])
  doc cap (1) ([object HTMLImageElement])
  win cap (1) ([object HTMLBodyElement])
  doc cap (1) ([object HTMLBodyElement])
  doc t+b (2) ([object HTMLDocument])
  win t+b (2) ([object HTMLDocument])

In Safari 2.0.4 (419.3) (I am told, and after "fixing" the test):

  doc cap (1) ([object IMG])
  win cap (0) ([object HTMLDocument])
  win t+b (0) ([object HTMLDocument])

These results are all different and all wrong. There is no event phase
`0`, during the phase `2` we gurantee that e.target == e.currentTarget,
during the phase `1` we gurantee that e.target != e.currentTarget, and
we require to dispatch the 'load' event to the Document. I understand
the purpose of this thread is to determine what actually should happen
as far as the Web API Working Group is concerned and to reflect that
in the DOM Events and Window specifications.
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 

Received on Friday, 29 December 2006 22:42:36 UTC