0

the eval function is using a string and calculate it yeah ? Isthere a function that takes an string like "console.log (lol)" as a parameter and execute it?

An exemple of what i need :

execute("for(var cpt=0;cpt<5;cpt++){alert('lol');}");

Its because i need to execute the code asked by the client, thanks :D

Antoine Duval
  • 342
  • 3
  • 20
  • 2
    Just a warning, this is a security **nightmare** . . . allowing the user to enter in code and then executing whatever it is that they've entered will allow them to cause an innumerable amount of trouble. – talemyn Mar 15 '15 at 17:24
  • possible duplicate of [How to execute a JavaScript function when I have its name as a string](http://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string) – MaxZoom Mar 15 '15 at 17:33
  • Gentlemen, it would be a security nightmare anywhere except code on the client, that is executed in the browser that generated it. If I read this right, he's trying to use it where it would be safe. – Joshua Mar 15 '15 at 22:50

1 Answers1

-1

Try:

eval("for(var cpt=0;cpt<5;cpt++){alert('lol');}");
Ben Aubin
  • 5,542
  • 2
  • 34
  • 54