Jump to content

importing js inside a js file


Destramic

Recommended Posts

You would create a new script html element with the source pointing to your javascript file. Append that file to the document head,

 

eg.

var scr = document.createElement('script');
scr.src = 'my_js_file.js';
document.getElementsByTagName('head')[0].appendChild(scr);

If the scripts are depending on each other, you would need to check the load status of each file (e.g. use the onstatuschange - complete or loaded - for IE and onload for other browsers).

 

The only other way to load scripts using javascript is to request the file using ajax and eval the result text.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.