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

    window.onload without reference to asynchronous dependencies

    window.onload doesn't fire until all external dependencies are resolved, right? But image loading is asynchronous, and a DOM structure doesn't need all the images to have loaded before it can be accessed.

    So is there a way to detect the state where the DOM is ready, without reference to asynchronous dependencies?
    "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
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    I don't know whether such a mechanism exists, but you could always try checking whether readystate or onreadystatechange can bew used for it. I belive they're implemented in newer moz versions, op7, iem and iew. I don't know about saf, though.

    If they don't work, try ondocumentready or oncontentready in ie.
    Last edited by liorean; 04-19-2004 at 02:20 PM.
    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

  • #3
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by brothercake
    window.onload doesn't fire until all external dependencies are resolved, right? But image loading is asynchronous, and a DOM structure doesn't need all the images to have loaded before it can be accessed.

    So is there a way to detect the state where the DOM is ready, without reference to asynchronous dependencies?
    Onload fires only after all the media, images, et c have loaded, right?

    Do you have a test case where onload fires and images are not yet loaded? I've never seen that happen.

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    It doesn't - but what he was asking for was a method of doing just that.
    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

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Exactly

    I shall try some of those ideas and post the results.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #6
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    Why not the old script before closing body tag?


    <script type='text/javascript'>
    window_loaded();
    </script>
    </body>
    </html>

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well I don't want to to impose restrictions on where in the source code the scripting has to be.

    But would that reliably work anyway? Isn't that just the same as calling the initialising function from there, and hence vulnerable to the page DOM possibly not being ready at all, as it gets to that script before the document has finished rendering ..?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #8
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    At that point, the browser has the whole document (except the closing tags for body and html, but that's OK) You basically have the whole document, but media (images, movies, et c) will still be downloading You can call document.getElementsByTagName w/o unexpected results, or do any other DOM stuff.

    If you find another way to do it, post it up - I'd like to know.

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I still wouldn't be happy with that ... it would make me nervous. I had that thought a while ago and I was talked out of it DOM works without window.onload

    Anyway I still haven't tried any of this ... so many things ...
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

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