www.webdeveloper.com
Results 1 to 6 of 6

Thread: Calling on another page of javascript functions

  1. #1
    Join Date
    Apr 2004
    Posts
    13

    Calling on another page of javascript functions

    I designed a page which has a background that dynamically changes color. To do so, I had to write several javascript functions. I hope to incorporate the background into another page I am making. Is there a way to have the new page call on the other? I would rather not resort to simply copying the one page and pasting it into the other.

  2. #2
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    If you put the JavaScript code (and only the script code, not the HTML <script> tags or anything) into a seperate .js file, you can load it using:

    <script type="text/javascript" src="example.js"></script>

    Adam
    "If youíre not using valid HTML, then you havenít created a Web page. You may have created something else, but it isnít a Web page." - Joe Clark

    Do something amazing (USA) | Make Poverty History

  3. #3
    Join Date
    Apr 2004
    Posts
    13
    Will the page still be able to start a function in the .js file when it loads, or will I need to call the javascript?

  4. #4
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    You can call the function onload in the body tag, or you can put it in the function itself.

  5. #5
    Join Date
    Apr 2004
    Posts
    13
    As of yet, in my javascript, the series begins with function startshift(). This function begins when the page loads. In the main page, to which the script is being called, do I need to use a special code, because including onLoad="startshift()" in the <body> tag is not working. I recieve an error message saying that there is an "object expected." I'm assuming that it's expecting the function it cannot find.

    Is there something I'm missing?

  6. #6
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    If you linked it properly, it has to work. You could also put window.onload = function() { startshift(); } at the beginning, before the function declaration itself. But if the body tag bit aint working, then the .js file probably isn't linked properly;

    <script type="text/javascript" src="whatever.js"></script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles