Posted By

studioevoque on 06/18/11


Tagged

jquery


Versions (?)

Load a JavaScript file dynamically


 / Published in: JavaScript
 

URL: http://www.ejeliot.com/blog/109

you need jQuery already loaded for this to work

  1. function loadScript(sScriptSrc, oCallback) {
  2. var oHead = $('head')[0];
  3. var oScript = document.createElement('script');
  4. oScript.type = 'text/javascript';
  5. oScript.src = sScriptSrc;
  6. // most browsers
  7. oScript.onload = oCallback;
  8. // IE 6 & 7
  9. oScript.onreadystatechange = function() {
  10. if (this.readyState == 'complete') {
  11. oCallback();
  12. }
  13. }
  14. oHead.appendChild(oScript);
  15. }

Report this snippet  

You need to login to post a comment.