I need a function in my currently building web project. Users are able to input their own Javascript code into <textarea> and run it after clicking a <button>. I have no idea about how to implement it. Could anyone help me with that? Thanks!
1 Answer
The most straight forward way that I can think to do this would be to use the eval() function. You would read the input code from the <textarea> and then pass it to eval(codeString) which would execute it.
With the above said there are security risks with using eval and there are probably better (more complex) ways to do what you want but for something simple I think eval() could work for you.
EDIT: So long as you're only running code this particular user gave you, and aren't letting users run other people's code, there is no security risk - @Niet the Dark Absol