We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

1man on 03/14/07


Tagged

ajax xml domain security json


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

korzhik


Ajax Insert Dynamic "script" into "head"


Published in: JavaScript 


Part of the script tag hack. Allows you to create a script tag on the fly from a url. The url could be a file containing info such as JSON or XML. Used in Ajax for crossing domains.

  1. function getScript(url){
  2. var scriptTag = document.createElement("script");
  3. scriptTag.setAttribute("type", "text/javascript");
  4. scriptTag.setAttribute("src", url);
  5. document.getElementsByTagName("head")[0].appendChild(scriptTag);
  6. }

Report this snippet 

You need to login to post a comment.