Appear in Online Interview to test your skills and be ready for job!
Twitter Twitter LinkedIn YouTube Google
Be Interview ready ! | Search
Submit content and win cash & prizes monthly.
Winners

Win Prizes

Announcements
Like us on Facebook
Sponsor
Top Codes Author
Fri, 25-Apr-2014 Authors
All Time Authors
Satyapriyanayak
11600
Jayakumars
8120
Niladri.biswas
6000

Latest members | More ...


(Statistics delayed by 5 minutes)

How to load another .js file in a .js file?

Poster
Posted by Poster under JavaScript on 3/1/2009 7:31:31 AM | Views : 5312 | Status : [Member]

Lets say you have a .js file and you want another .js file to load from this .js file without addding another <script> tag to load .js file in every page of the website, you can use following function

function addJavascript(jsname) {

var th = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
s.setAttribute('type','text/javascript');
s.setAttribute('src',jsname);
th.appendChild(s);
}


You can call above function like this
addJavascript('/yourjsfile.js');


Found interesting? Add this to:



Comments or Responses


Login to post response.

Comments / Responses
Select text & click toolbar to format. Formatting appears in viewmode only. HTML Tags are not allowed.
Bold Italic Underline Paragraph Title Code  Link 
 Wait ... Processing ..... please wait.