in JavaScripting

What's up with document.onload?

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

  1. 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.

Comments are closed.