javascript – Embed js file in another – Stack Overflow

javascript – Embed js file in another – Stack Overflow

You can not embed a JavaScript file in another. But you can load more JavaScript files in dynamically with a function such as this one.

function loadJS(file) {

// Grab the head element

var head = document.getElementsByTagName(‘head’)[0];

// Create a script element

var script = document.createElement(‘script’);

// Set the type

script.type = ‘text/javascript’;

// Set the source file

script.src = file;

// Add the script element to the head

head.appendChild(script);

}

via javascript – Embed js file in another – Stack Overflow.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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