JSON-in-script loader



/**
 * Loads an external javascript source by creating a <script> tag
 * and injecting it into the DOM.
 * @param {string} src Url of the js source 
 * @param {string} opt_id An optional id for the <script> tag
 */ 
function load(src, opt_id) {
  var scripts = document.getElementsByTagName('script');
  
  // prevent from loading same script twice
  var alreadyLoaded = false;
  for (var i = 0, script; script = scripts[i]; i++) {
    if (script.src == src) {
      alreadyLoaded = true;
      break;
    }
  }
  
  if (!alreadyLoaded) {
    var scriptElement = document.createElement('script');
    if (opt_id) {
      scriptElement.setAttribute('id', opt_id);
    }
    scriptElement.setAttribute('type', 'text/javascript');
    scriptElement.setAttribute('src', src);
    document.documentElement.firstChild.appendChild(scriptElement);
  }
};

3 comments:

cmtech said...

Has anyone said that your article is very good yet? I will give you a single ten for this achievement. Thanks

Cửa lùa gỗ công nghiệp

rekha verma said...



We have a List of Girls who are in financial problems. They need your help. They are ready to sleep with you in some small amounts. Call us for their contact no and help them. To book an escort just drop a call to the given number and ask them what kind of service you want!. You will also WhatsApp us for the availability of our Russian Escorts in Surat. If you’re in the end determined and ready to enjoy the amusing of being at duration the corporate of one of our beautiful girls. Check our other Services...
Russian Escorts in Udaipur
Russian Escorts in Udaipur
Russian Escorts in Vasant Kunj
Russian Escorts in Vasant Kunj
Russian Escorts in Vasant Kunj

Escorts Service in Delhi said...

russian escort gurgaon
russian escort gurgaon
russian escort gurgaon
gurugram escort service
gurugram escort service