SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Including files in javascript

    Hi guys,

    New to javascript, and am having trouble linking files together.

    I have a class A that utilizes class B. However, since it is a .js file, I am having trouble linking them. I could link it from the master page that calls class A, but then the order of the includes would matter (and overall doesn't seem like a nice way to do it.)

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This isn't like PHP where you can include/require other files. The best way really is to put them both in the <head> in your HTML document. Your server side script should be able to work out when and where to include them, and whether it should go before or other JS files in HTML source order.

    You could, I suppose, get file B via an XHR request and then eval() the string you get, but that is much less nice I think.

  3. #3
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also create a new script element. Than set the src to the required script.

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •