import some js code in a .js file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ricardo Garcia

    #1

    import some js code in a .js file

    hi, how could i import a js file in another js file???
    what i want is the equivalent to:
    <script type="text/javascript" src="file.js"></script>
    in html


    Thanks


  • Randy Webb

    #2
    Re: import some js code in a .js file

    Ricardo Garcia wrote:
    [color=blue]
    > hi, how could i import a js file in another js file???
    > what i want is the equivalent to:
    > <script type="text/javascript" src="file.js">
    > in html[/color]


    document.write( '<script type="text/javascript" src="file.js"></script>')
    is the easiest way. There are other ways though.

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    • RobG

      #3
      Re: import some js code in a .js file

      Ricardo Garcia wrote:[color=blue]
      > hi, how could i import a js file in another js file???
      > what i want is the equivalent to:
      > <script type="text/javascript" src="file.js"></script>
      > in html
      >[/color]

      If you are creating an HTML page, you don't need to
      explicity import JavaScript files, just put a reference
      to the files containing the functions you want to use:

      <script type="text/javascript" src="file01.js" ></script>
      <script type="text/javascript" src="file02.js" ></script>
      ...
      <script type="text/javascript" src="filenn.js" ></script>

      Just call functions in the files, you can add as many
      as you like. Functions from one file can use functions
      in another file quite happily.

      If you are using some other scripting environment
      (e.g. Mozilla's Rhino), you may require some other method.

      Cheers, Rob.

      Comment

      Working...