Include js file into another js file

In the last days I had a big problem: how I can include a javascript file into another javascript file without use the tag script?
Searching on Google I have found the answer to my problem with this simple javascript function:

function addJavascript(jsname,pos) {
     var th = document.getElementsByTagName(pos)[0];
     var s = document.createElement(‘script’);

the variable jsname is the name of the javascript file
the variable pos is the tag where you want to add the file

An example of usage:

It works for me, I hope for you too!

[ the original news ]

This entry was posted in javascript. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s