Re: DOM3 Events call today/tonight?

Garrett Smith <dhtmlkitchen@gmail.com> wrote:

> On Wed, Feb 25, 2009 at 10:16 AM, Olli Pettay <Olli.Pettay@helsinki.fi>
wrote:
> > On 2/25/09 7:46 PM, Garrett Smith wrote:
> >>>
> > > > unfortunately I have not been able to catch up with Doug (a
> > > > combination of both of us travelling and then I had a minor accident
> > > > that put me out of commission for a while), so as far as I know we
> > > > have no agenda planned for tonight's call.

> > HTML 5 says that "If the Document is in a browsing context, then queue a
> > task to fire a load  event at the Document's Window  object." And that
> > is what at least Gecko does.
> >
> > 'load' is a special event in many ways. 'load' events dispatched
> > somewhere in document (for example for <img>) don't propagate to
> > 'window'. And the 'load' event which is dispatched to 'window', has
> > 'document' as its target. This all is required for backwards
> > compatibility.
> >
> 
> I see. window does implement EventTarget.  In Webkit/Gecko, the
> |event.target| is document.

> [code and results snipped: see message ID:
<c9e12660902251326w50b164edr7f98052ace6317de@mail.gmail.com> ]


I spent some time trying to work out what on earth was going on in different
browsers (Firefox, Opera, Safari, IE and our own) and came to the conclusion
that they were all different, and depending on exactly how you added the
listener (and in what order they were set!), you got different behaviour. So
whilst you've already tried addEventListener on the window and document
objects directly, the (full?) list of ways that content can use to be
notified that the "document is loaded" is, AFAICT:

window.addEventListener()
document.addEventListener()
Setting document.onload in script
Setting window.onload in script
Putting an onload attribute on the body element
Putting an onload attribute on a frameset element

The frameset one is even more interesting, because if you write something
like this:

<html>
<script>
function f() { alert( 'f()' ) };
function g() { alert( 'g()' ) };
</script>
<frameset rows=* onload="f()">
  <frameset cols=* onload="g()">
    <frame>
  </frameset>
</frameset>

Only g is called.  I think that's unintuitive, tbh.  The reason why is that
the event handlers are compiled when the body/frameset node is attached to
the document tree, but they are then stored as if they were intrinsic events
for the #document node (i.e. they act as proxies for #document, as you can't
put attributes on #document directly), so the last one seen by the parser
wins.


> Opera [... supports various other things ...]
> I wonder why Opera implemented that.

This sounds more like either a symptom of trying to be compatible with other
browsers, or an unnoticed side-effect due to the way events are implemented.
I've had the same sort of troubles trying to implement something that's both
vaguely sensible and yet "compatible with the web".  I did build a table of
what supported what sometime last year, but I can't find it right now.  I'll
keep looking for it, as it may contain useful information.


-- 
Stewart Brodie
Software Engineer
ANT Software Limited

Received on Thursday, 26 February 2009 12:27:49 UTC