Skip to content

Instantly share code, notes, and snippets.

@bryanforbes
Created May 16, 2011 20:52
Show Gist options
  • Select an option

  • Save bryanforbes/975353 to your computer and use it in GitHub Desktop.

Select an option

Save bryanforbes/975353 to your computer and use it in GitHub Desktop.
script inject eval
var globalEval = (function(global, doc){
global.__dojoEvalInfo__ = {};
var resultId = 0,
head = doc.getElementsByTagName("head")[0] || doc.documentElement;
return function(text){
var script = doc.createElement("script"),
id = resultId++, sText, result;
script.type = "text/javascript";
sText = "__dojoEvalInfo__[" + id + "].result = eval(__dojoEvalInfo__[" + id + "].text);";
global.__dojoEvalInfo__[id] = { text: text };
try{
script.appendChild(doc.createTextNode(sText));
}catch(e){
script.innerText = sText;
}
head.insertBefore(script, head.firstChild);
result = global.__dojoEvalInfo__["result"+id];
script.parentNode.removeChild(script);
delete global.__dojoEvalInfo__[id];
return result;
};
})(this, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment