DOMContentLoaded

19 views
Skip to first unread message

Alex Robinson

unread,
Aug 20, 2007, 12:48:04 PM8/20/07
to base2-js
I must be being super dense, but I can't see how to actually use
DOMContentLoaded (outside of Gecko, that is). My guess was that you
did something like this:


// somebody set up us the bomb - all your base2 window objects are
belong to us
base2.DOM.EventTarget(window);

// works
window.addEventListener("load", myInit, false);

// doesn't work
window.addEventListener("DOMContentLoaded", myInit, false);


Obviously when I say "doesn't work", it works in assorted Geckos,
Safari and Opera. I mean it doesn't work in IE (6 or 7)


So, just how is one supposed to actually make use of the support that
Base2 provides for DOMContentLoaded?

Dean Edwards

unread,
Aug 20, 2007, 1:02:09 PM8/20/07
to base...@googlegroups.com
Alex Robinson wrote:
> I must be being super dense, but I can't see how to actually use
> DOMContentLoaded (outside of Gecko, that is). My guess was that you
> did something like this:
>
> // doesn't work
> window.addEventListener("DOMContentLoaded", myInit, false);
>

The window object is not part of the DOM. Use this instead:

document.addEventListener("DOMContentLoaded", myInit, false);

-dean

Alex Robinson

unread,
Aug 20, 2007, 2:29:23 PM8/20/07
to base...@googlegroups.com
>The window object is not part of the DOM. Use this instead:
>
>document.addEventListener("DOMContentLoaded", myInit, false);


Ah right. And now I've tracked down my incorrectly overlapping script
tags, it works lovely.

However, just before moving on...

The standards-based way of doing this (in so far as DOMContentLoaded
is a standard?) is to do

window.addEventListener("DOMContentLoaded", myInit, false);

(or am I wrong? if so, please discount the following)

This will need flagging up in the docs. Or perhaps the code could
make a special exception if the element passed is the window object
and the handler is DOMContentLoaded, flipping the element that the
handler is set on to document? Just a thought.

Dean Edwards

unread,
Aug 20, 2007, 3:31:38 PM8/20/07
to base...@googlegroups.com
Alex Robinson wrote:
> The standards-based way of doing this (in so far as DOMContentLoaded
> is a standard?) is to do
>
> window.addEventListener("DOMContentLoaded", myInit, false);
>
> (or am I wrong? if so, please discount the following)
>

Show me the standard for this.

-dean

Alex Robinson

unread,
Aug 21, 2007, 8:20:32 AM8/21/07
to base...@googlegroups.com
>Show me the standard for this.


Colour me nine shades of wrong.

Obviously, DOMCOntentLoaded is not actually a standard. What I meant,
was that I thought that Gecko (and Opera) required the handler to be
attached to the window object. I now realise, post actually bothering
to test it, that my supposition was tosh, and that using document
works just as well.

Reply all
Reply to author
Forward
0 new messages