×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: pery mimon
Added: Feb 22, 2017 11:41 AM
Views: 9
Tags: no tags
  1. function loadScript(scriptFileURL){
  2.     return new Promise(function (response, reject) {
  3.         // var script = new Element("script", {
  4.         //     src: scriptFileURL, type: "text/javascript"
  5.         // });
  6.         var script = document.createElement('script');
  7.         script.setAttribute('src', scriptFileURL);
  8.         script.setAttribute('type', "text/javascript");
  9.  
  10.         document.head.appendChild(script);
  11.  
  12.         script.onload = script.onreadystatechange = function(){
  13.             if (!this.readyState ||
  14.                 this.readyState == "loaded" || this.readyState == "complete") {
  15.                 response();
  16.             }
  17.         };
  18.     });
  19.  
  20. }