jesobreira

Javascript import js file

Jan 15th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function loadScript(url, callback)
  2. {
  3.     // Adding the script tag to the head as suggested before
  4.     var head = document.getElementsByTagName('head')[0];
  5.     var script = document.createElement('script');
  6.     script.type = 'text/javascript';
  7.     script.src = url;
  8.  
  9.     // Then bind the event to the callback function.
  10.     // There are several events for cross browser compatibility.
  11.     script.onreadystatechange = callback;
  12.     script.onload = callback;
  13.  
  14.     // Fire the loading
  15.     head.appendChild(script);
  16. }
Add Comment
Please, Sign In to add comment