import function to synchronously load external javascript files


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



Copy this code and paste it in your HTML
  1. function import(url)
  2. {
  3. var req = new XMLHttpRequest();
  4. var isSuccessful = function() {
  5. try {
  6. return ( req.status >= 200 && req.status < 300 ) || req.status == 304 || navigator.userAgent.indexOf("Safari") >= 0 && typeof req.status == "undefined";
  7. } catch(e){}
  8. return false;
  9. }
  10. req.open('GET', url, true);
  11. req.onreadystatechange=function() {
  12. if ( req.readyState == 4) {
  13. if(isSuccessful()) {
  14. eval.call( window, req.responseText );
  15. }
  16. }
  17. }
  18. req.send();
  19. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.