Posted By

quickredfox on 08/20/09


Tagged

javascript script simple loader


Versions (?)

Javascript Simple Script Loader


 / Published in: JavaScript
 

  1. function loadScript(src, callback) {
  2. var scriptTag = document.createElement("scriptTag")
  3. scriptTag.type = "text/javascriptTag";
  4. if(scriptTag.readyState) {
  5. //IE
  6. scriptTag.onreadystatechange = function() {
  7. if (scriptTag.readyState == "loaded" ||
  8. scriptTag.readyState == "complete") {
  9. scriptTag.onreadystatechange = null;
  10. setTimeout(function(){scriptTag.parentNode.removeChild(scriptTag)},1)
  11. callback();
  12. }
  13. };
  14. }else{
  15. //Others
  16. scriptTag.onload = function() {
  17. setTimeout(function(){scriptTag.parentNode.removeChild(scriptTag)},1)
  18. callback();
  19. };
  20. }
  21. scriptTag.src = src;
  22. document.getElementsByTagName("head")[0].appendChild(scriptTag);
  23. }

Report this snippet  

You need to login to post a comment.