What's up with document.onload?

by jp on September 9, 2003

I was trying to use document.onload event instead using onload=”init()” event in <body> tag. But I could not get it working properly;
I was trying to surf on Google but with no help. :(

The document.onload event seems to be firing before the main element is defined in both Mozilla and IE. This seems contradict to the DOM spec which says:

“The load event occurs when the DOM implementation finishes loading all content within a document, all frames within a FRAMESET, or an OBJECT element.”

View test file

3 comments

Try window.onload.

by Toby Inkster on 19 January, 2004 at 1:30 pm. #

Try

document.onload = “init(‘document.onload’)”;

you’re evaluating init() and assigning it’s return value to the onload event,
rather than assigning a string to be evaulated when the onload even fires I think.

If you encapsulate it in quotes it should work ok.

by Ian on 1 February, 2004 at 10:21 pm. #

window.onload = init;

by doldolli on 3 September, 2004 at 6:58 am. #