Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    near Oswestry
    Thanked 0 Times in 0 Posts

    DOM works without window.onload

    This is slightly worrying - I was under the impression that properties of objects in mozilla are not available until the entire document has finished loading; but I just tried out a complex menu script I'm working on, processing the <ul> without window.onload, just ensuring that the initialisation calls happen at the end of the script, which is after the <ul> in the document.

       ... blah ...
    //object constructor
    //a few methods
    //call object constructor
    And it works fine. But I feel worried. Are there circumstances under which it won't work so fluidly, or am I being paranoid for nothing?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  2. #2
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    metro DC
    Thanked 18 Times in 18 Posts
    Why would you need the page to fully load? The DOM is dynamic, especially so during page rendering. The entire <ul> node has been created in memory by the time your script is executed, so there shouldn't be any issues. Things to be concerned about would be accessing childnodes and siblings during page load, but that is the only thing I'd be concerned about.

  3. #3
    Master Coder
    Join Date
    Feb 2003
    Umeň, Sweden
    Thanked 83 Times in 74 Posts
    Well, the thing is rather that the document is not finished yet, and thus the user agent doesn't necessarily provide getElementById, getElementsByTagName, body or documentElement properties of the document yet. Thus you can't rely on those being present, or if they are present, that they will work as they should. The node you want to handle itself, though, will be present and you can do anything you want with it.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts