Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Client Scripting
Expertise: Beginner
Feb 17, 2000

Place JavaScript In Separate Files

Question:

I want to create a library of generic JavaScript functions. Is it possible to write different functions in different files, and use the functions within other files by "including" these files? Like in C, you can use the #include directive to include other functions.

Answer:

Yes, you can put your JavaScript into files that you reference from multiple pages. You should make sure that your JavaScript code files use the .js extension. In addition, your shared code library should be stored in a directory on your Web server that is accessible over the Web, just like an image. The syntax for including your code is:


Make sure to include the trailing tag.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date