Reputation: 1968
I have a page that has a textarea called Program. A user can put Javascript code in the Program window, and my page will execute this Javascript code and place the result in an output window.
One way I've thought of accomplishing this is to essentially copy and paste the Program textarea into an empty function, and then call that function. I'm fairly new to Javascript so I don't know if something like this is possible. Any advice is appreciated!
Upvotes: 2
Views: 36
Reputation: 11498
myFunction = new Function(mytextarea.value);
But please, put it in an iframe.
myIframe.srcdoc = "<!DOCTYPE html><html><head><script>"+mytextarea.value+"</script></head><body>You could put stuff here.</body></html>";
Upvotes: 1