Search
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Codes Author
Tue, 22-Jul-2014 Authors
All Time Authors
Satyapriyanayak
12160
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 : 5852 | 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