SitePoint Sponsor

User Tag List

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

    Calling a function from multiple pages - onLoad

    Hi All,

    I am new to this forum and wondering if someone can help me.
    I have recently joined a company and am helping to maintain their old web site.

    JavaScript is not my strong point though and I have found that the previous web editor has a lot of repeat functions on the pages.

    My idea is to create an external .js file and just call the function...it is for a rotating banner ad.
    The problem is the the function is called in the <Body> tag..this means that I have to change 100's of pages by adding the call function to the tag on every page.

    Is there a way I can call the function as well as adding the function to the onLoad event.

    I have tried adding "window.onload = rotateBanner;" to the beginning of my javaScript but it does not seem to work...what am I doing wrong....please help.

    Charmie

  2. #2
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not a JavaScript person but you should be able to call the functions from within a function (especially since a page can have but one onload event handler anyway).

    Something like this perhaps...

    Code:
    window.onload = function() {
    	functionName();
    	// another function, if needed, would be called here
    	// another function, if needed, would be called here
    	// and so forth
    }
    It's not the most efficient way, mind you, but it should work. Besides, this will also mean you can just remove the onload code from the <body> tag completely and call everything externally.


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
  •