How do I check if the window has been loaded?

Discussion in 'JavaScript' started by Imozeb, Apr 8, 2010.

  1. #1
    I have javascript in my <head> tag that needs some <div> tags in the body section to be loaded. How do I only execute the javascript if the window is done loading? (The javascript is in an external sheet if that matters.)

    Thanks!

    ~imzoeb :)
     
    Imozeb, Apr 8, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    If I understood you correctly you have to do it by

    
    window.onload = function(){
    // your code
    }
    
    Code (markup):
    If not - explain in details.
     
    s_ruben, Apr 9, 2010 IP
  3. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    My script works fine in IE but when I try to run it in FireFox the rollOvers don't work. I checked FireFox's error console and it states that my roll over functions have not been defined when I rollOver the button. I don't know why this is happening but I assumed that the window needs to be completely loaded before it reads the Javascript. I'm not sure if this is the problem because I've been using IE to test my script all this time and now I am trying to make it cross-browser. Any ideas?

    Thanks.
     
    Imozeb, Apr 9, 2010 IP