Created
May 16, 2011 20:52
-
-
Save bryanforbes/975353 to your computer and use it in GitHub Desktop.
script inject eval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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