SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mutiple onload function

    How can I put

    onLoad="P7_initTP(3,1);P7_TPurl()"

    and

    onLoad="javascript:load_dates_values();"

    into a external javascript file so I can call on both to work on the same page?



    Thanks

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just do this in your file:
    Code javascript:
    P7_initTP(3,1);
    P7_TPurl();
    load_dates_values();
    And preferably put the code they call also in the same file.

    Then put the reference to this file at the bottom of the body just before the closing </body> tag.

    HTML Code:
    <!-- body html -->
    <script type="text/javascript" src="stuff.js"></script>
    </body>
    </html>

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seems to work great..

    I thought it would need to be a function type setup to make it work.

    Thanks

  4. #4
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's another great solution that's been around the web for years. Well tested, and excellent crossbrowser functionality

    function addLoadEvent(func) {

    //assigns a variable for the onload event
    var oldOnload = window.onload;

    // checks to see if there is a function already assigned to onload
    if (typeof window.onload != 'function') {
    window.onload = func; // if not, onload executes the function
    }

    // otherwise the variable is called to run the previously called function(s)
    else {
    window.onload = function() {
    if (oldOnload) {
    oldOnload(); //calls the old function(s)
    }
    func(); //calls the new function
    }
    }
    }

    // Call the functions you want to insert, one per addLoadEvent
    addLoadEvent(ecClock);
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.


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
  •