Dynamically Insert External JavaScript with JavaScript


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



Copy this code and paste it in your HTML
  1. var headID = document.getElementsByTagName("head")[0];
  2. var newScript = document.createElement('script');
  3. newScript.type = 'text/javascript';
  4. newScript.src = 'http://www.somedomain.com/somescript.js';
  5. headID.appendChild(newScript);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.