Skip to content

Instantly share code, notes, and snippets.

@westc
Created October 23, 2014 12:11
Show Gist options
  • Save westc/c36c822b0227b01f8914 to your computer and use it in GitHub Desktop.
Save westc/c36c822b0227b01f8914 to your computer and use it in GitHub Desktop.
Global Namespace Evaluation of JavaScript Using Data URIs (DANGEROUS!!!)
/**
* 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