Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Feb 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Include file in javascript.js file

    Hi,

    I need to include one javascript (.js) file in another javascript file (.js). Does anyone know if this is possible, and if so how it can be done? Right now the only way I can work around it is by entering two sets of <SCRIPT> tags in each page.

    Since all pages need script01.js, and some need script02.js and others need script03.js, it would be cool if the script02.js and script03.js files could incorporate the script01.js files instead of needing to always reference two scripts in the web pages.

    Does this make sense?

    Any help would be appreciated.

    Thanks in advance.

    -djz

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Include file in javascript.js file

    I believe that included .js files are conceptually the content of a pair of <SCRIPT> and </SCRIPT> tags. Since I do not think you can "nest" <SCRIPT> tags, I do not believe you can use includes in your .js files.

  3. #3
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Include file in javascript.js file

    Yes you can. But it requires a little setup...and access to the server. An include file is processed through an ISAPI application. (ssinc.dll to be exact). That .dll 'looks' for include tags, grabs the necessary files, and ports them into the 'original' document, then hands them off to the next process. You can do this for any file (.asp, .js, htm, etc.) Here's the trick, the ssinc.dll ISAPI application needs to know what extensions it has to work on. To do this (and these are instructions for an IIS server), go into your web's properties. On the Home Directory Tab (it can be named something different depending on if it is a shared location, and local directory, or redirected URL), and click the Configuration button near the bottom. The first tab that pulls up should be 'App Mappings'. In this list, you will find all of the mappings on your machine. Click Add. Then browse for the ssinc.dll (it should already be in the right directory, just switch the file type from .exe to .dll. (it is in the inetsrv folder within your System32 directory) and then put .js in for the extension. Now you can include .js files.

    Just a side note on this. You can have a lot of fun with the ISAPI mappings. I have our current website setup to use the ASP ISAPI application on both .asp AND .htm files....so some of our normal 'htm' files are actually running a few .asp scripts. I claim NO FOUL if this goofs something though! <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

  4. #4
    New Lounger
    Join Date
    Feb 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Include file in javascript.js file

    Thanks for the tip. I'll try it out today and let you know how it goes.

    -djz

  5. #5
    New Lounger
    Join Date
    Feb 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Include file in javascript.js file

    Hi,

    I followed your directions, but now I'm not sure how to go about including the second .js file in the first.

    The primary .js file is referenced in all the web pages as:

    The secondary .js file, which I would like to include in the primary, is "/CODEREUSE/menucode.js"

    I tried including it using the following line at the beginning of the "menu.js" file:

    // #INCLUDE VIRTUAL="CODEREUSE/menucode.js"

    That does not work, unfortunately. (BTW, I know it does not work because the "menucode.js" file creates classes that the primary file uses, and if the code in "menucode.js" is not available it returns an error when it tries to create an object based on that class.)

    I have setup the "ssinc.dll" to execute for ".js" files by following your directions. What else do I need to do now to get the include file to be included?

    Thanks,

    -djz

  6. #6
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Include file in javascript.js file

    My include statements say this:

    < !-- #include file = "searchform.inc" -- >

    (Without spaces after the less then and before the greater then....(Thanks Jefferson...didn't even notice that it was missing))

    The included file needs to be in the same folder or subfolders (which I think you already have....just mentioning it).

Posting Permissions

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