SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast Josty's Avatar
    Join Date
    Jun 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inclue javascript file in another javascript file

    Hi, is it possible to use functions from javascript file A.js in javascript file B.js?

  2. #2
    SitePoint Zealot sajjad's Avatar
    Join Date
    May 2005
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Try use this,

    var script = document.createElement("script");
    script.setAttribute("type", "text/javascript");
    script.setAttribute("src", "path/to/file.js");
    document.getElementsByTagName("head")[0].appendChild(script);

  3. #3
    SitePoint Enthusiast Josty's Avatar
    Join Date
    Jun 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hum, seems like an good idea! Short and nice! Thank you!

  4. #4
    SitePoint Zealot sajjad's Avatar
    Join Date
    May 2005
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No Problem at all

  5. #5
    Caveat surfer Buddy Bradley's Avatar
    Join Date
    May 2003
    Location
    Cambridge, UK
    Posts
    2,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sajjad
    Dear Try use this,

    var script = document.createElement("script");
    script.setAttribute("type", "text/javascript");
    script.setAttribute("src", "path/to/file.js");
    document.getElementsByTagName("head")[0].appendChild(script);
    That doesn't seem to be answering the original question, which is 'yes, you can refer to functions in other Javascript files'.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Location
    Leeds, UK
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Buddy Bradley
    That doesn't seem to be answering the original question, which is 'yes, you can refer to functions in other Javascript files'.
    didn't him supplying a working script say "yes" enough?


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
  •