Link to home
Start Free TrialLog in
Avatar of afflik1923
afflik1923Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Reference external Javascript file from external javascript file - How?

It should be simple but I must be tired or crazy right now.
But how do I reference a javascript file from another javascript file.

In my particular case I need to import a JSON co library into a javascript file that is called from the main HTML page.
But that does not matter, I just need to know how to call a javascript file from another javacript file. (I of course know how to reference one from a HTML file).

Equivelant command in PHP would be require_once.

Thanks.
SOLUTION
Avatar of gam3r_3xtr3m3
gam3r_3xtr3m3
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunithnair
sunithnair

I dont think it is possible. Try this anyway inside the js file that in the child js file
document.write('<script type="text/javascript" src="basesrc.js"><\/script>');
 
or
 
var script = document.createElement("script");
script.setAttribute("type","text/javascript");
script.setAttribute("src", "basesrc.js");
document.getElementsByTagName("head")[0].appendChild(script);

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of afflik1923

ASKER

All suggestions good but the easiet and one I used was the omarked as accepted solution.