Created
October 23, 2014 12:11
-
-
Save westc/c36c822b0227b01f8914 to your computer and use it in GitHub Desktop.
Global Namespace Evaluation of JavaScript Using Data URIs (DANGEROUS!!!)
This file contains 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
/** | |
* Evaluate a string of JavaScript code in the global namespace. | |
* NOTE: This differs from eval() in that it doesn't return a value. | |
* @param {string} code The JavaScript code to be executed in the global namespace. | |
*/ | |
function globalEval(code) { | |
var script = document.createElement('script'); | |
script.src = 'data:application/javascript;charset=utf-8,' + encodeURIComponent(code); | |
(document.getElementsByTagName('head')[0] || document.body).appendChild(script); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment