SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    When to fire scripts that influence the site's layout?

    Hellos,

    I have a two column website, with content in both. Now, I'd like to set the height of both columns to the same height. I have managed to do that in my script. However:

    The only problem now is WHEN to load that script: Both columns have images that take a moment to load, depending on the visitor's download speed. My question is, what is the "best practice" (if there is any?) to load my script that fiddles with the layout? onLoad in the body isn't an option because my script requires the whole layout to be parsed already, and putting a delayed call to the script at the end of my HTML seems like the wrong way of doing it. Besides, with that I still have the problem of slow loading times.

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What about window.onload = yourfunctionname;

    ??

    PS - if all your images had height/width attributes you shouldn't have a problem.
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by siteguru View Post
    What about window.onload = yourfunctionname;

    ??

    PS - if all your images had height/width attributes you shouldn't have a problem.
    window.onload... isn't that just the same as having onload="functionname();" in the Body tag?

    Also, I'll look into the height/width on images, ta

  4. #4
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also use a JavaScript framework that provides a document "ready" event. These fire before page load (including images etc.), when the DOM is ready for manipulation.

    You could, of course, roll your own implementation; but it gets a bit fiddly trying to maintain browser compatibility.


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
  •