SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Javascript Loading At The Last Stage

    Currently i am trying to force the javascript function to load last. So i placed it at the bottom before the body and call in using getElementById method. How can i declare a function using getElementById().innerHTML? Below are the sample code i have used. Thank you in advance...

    <span id="somethingloadlast"></span>

    <script> fucntion show () { coding....} </script>

    document.getElementById("somethingloadlast").innerHTML = "<script>show()</script>";

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you simply put the script (show()) at the bottom of the body instead of making another script do it?
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I cant do that cos i need to load JavaScript after the page has finish loading. As u can see from the code sample, i am trying to call a js function which is place after the <span> layer. is there any method to call this function on the top of the page?

  4. #4
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if you stick that script at the top of the page then it probably won't work because you're looking for an element ("somethingloadlast") which may not have been loaded yet.

    Why can't you just place that script (<script>show()</script>) just above the </body> tag? Do you not have access to the bottom of your document?

    I suppose you could use a DOM ready function like Dean Edward's...
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  5. #5
    Floridiot joebert's Avatar
    Join Date
    Mar 2004
    Location
    Kenneth City, FL
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does this function use document.write or something to write content inside that <span> element, and the script that defines that function is a 3rd party script like an ad banner or something ?


    If that's the case, what I do is go ahead and place the container at the bottom of the page with the script inside of it, then if it's supposed to be somewhere I can place with absolute positioning like 100px from the top I use CSS to position that container.
    Else I use the DOM methods to remove and re-insert the element where it needs to go.


Tags for this Thread

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
  •