Jump to content

  • Log In with Google      Sign In   
  • Create Account


Martin Wells

Member Since 04 Nov 2012
Offline Last Active Nov 09 2012 10:26 PM

#4997222 Javascript & HTML5: Loading of external scripts with javascript

Posted by Martin Wells on 04 November 2012 - 11:09 AM

I'm not entirely sure of the problem you're having. You can definitely load javascript files dynamically, and then execute them.

Why not just dynamically construct a script element, set the src attribute and then append it to the DOM, i.e.

[source lang="jscript"] var src = 'my.js; var script = document.createElement("script"); script.type = "application/javascript"; script.src = src; script.onload = function() { // ya! }; script.onerror = function () { throw('Could not load javascript file: ' + script.src); }; document.getElementsByTagName("head")[0].appendChild(script);[/source]

Am I missing something?


PARTNERS