SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Before onload?

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Temecula, CA
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Before onload?

    What happens (what events are there) before onload? Seems like there might not be any, but I thought I would ask as I would like to call an Ajax function as soon as the page begins to load so that it can be doing its thing while the page is loading.

    Any ideas on this?

  2. #2
    SitePoint Zealot bobber205's Avatar
    Join Date
    Sep 2006
    Location
    Oregon
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty sure that onload is the earliest event Javascript has access to.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You can start Javascripts running before the page finishes loading but the first event you can check for is the onload event. For example if you want to set up something that will run as soon as the object on a page having a particular id exists rather than waiting for the whole page including images to load then you can set up a loop to test for it (see http://javascript.about.com/library/blfastdom.htm for example code).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Temecula, CA
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This has given me some good thought. I will use the code that checks for the existence of the object but not where Chapman has suggested. I'm interested in firing off some Ajax so that it can get ahead of the page loading process. So, I'll initiate the Ajax call to my PHP then within the Ajax update function I'll use Chapman's code to check to see if all is well before going to the 'whatever.innerHTML = response;' line.

    Thanks.

  5. #5
    Caveat surfer Buddy Bradley's Avatar
    Join Date
    May 2003
    Location
    Cambridge, UK
    Posts
    2,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is an onDOMContentLoaded event in Mozilla that you can check for which will fire once the DOM has loaded but before any images, etc. IE doesn't have this, but it does have the defer attribute on script tags that accomplishes the same thing.

    Read this for more details.


Bookmarks

Posting Permissions

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