Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2005
    Location
    Arizona
    Posts
    336
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Having one js file call another js file?

    I just now learning how to create and use js files.

    I was wondering if you can have one js file have a call to another js file in it.

    I tried putting this as the the last line of a js file:

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

    I know you are normally suppose to leave off the <script></script> tags in the js file, but I thought I would try it anyway. Of course it didn't work, so if you can call another js file from with in the js file, how do you do it.

    PhotoJoe

  • #2
    gph
    gph is offline
    Regular Coder
    Join Date
    Apr 2005
    Posts
    161
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can document.write one file from another

    Code:
    document.write('<script type="text/javascript" src="tumbnail.js"><\/script>')
    which happens immediately

    Or you can bring a file in when needed

    Code:
    function newScript(js_src){
    var js=document.createElement('script');
    js.type='text/javascript';
    js.src=js_src;
    document.getElementsByTagName('head')[0].appendChild(js)
    }

  • #3
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Or you can take the actual code from the thumbnail file and paste it into the bottom of the other include file.

    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #4
    Regular Coder
    Join Date
    Oct 2005
    Location
    Arizona
    Posts
    336
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks "gph",

    Your first example is just what I was looking for. I will add the second one to my list of tips I'm saving in a word.doc for reference.

    Thanks "Basscyst",

    The first js file contains the variables and functions that are unique to that page. The second js file is for functions that will be used for all my tumbnail pages.

    I understand that once a js file has been loaded to the browser it is stored in the cache. So after the first tumbnail page has been display the javascript functions that are common to all my tumbnail pages will load from the browser cache and not the server which will save time and I think bandwidth use?

    The reason I want to have a js file for the variables and functions that are unique to each page is because I'm planning on finding away to use the same tumbnail page over and over again instead of creating 50 different tumbnail pages. I'm doing research on that problem right now.

    BTW I just publish the website that I have been working on:

    http://www.photojoe.ws

    If you want to see the tumbnail page that I have been working on, just choose the "Catalog of Pictures" from the menu on the left.

    PhotoJoe


  •  

    Posting Permissions

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