Wednesday, January 19, 2011

Inluding multiple javascript files via javascript

The problem is typical: How can I include a javascript library or multiple .js files with only 1 javascript include.


Basically, here's a quick sample using jquery, though obviously it can be done without it.


js1.js {
$('head').ready(function() {
$('head').append('<script language="JavaScript"
type="text/javascript" src="http://javascriptFile2.js"></script>');
});
$('head').ready(function() {
$('head').append('<script language="JavaScript"
type="text/javascript" src="javascriptFile3"></script>');
});
}

That's all there is to it. Now javascriptFile3 can access the methods of javasriptFile2.

No comments:

Post a Comment