Load a JavaScript file dynamically


/ Published in: JavaScript
Save to your folder(s)

you need jQuery already loaded for this to work


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.