Shazboticus S Shazbot Shazboticus S Shazbot - 2 years ago 141
Javascript Question

jQuery execute string as function

I want to pass in a jQuery command (in the form of a string) from server-side JS to client-side js. This allows me to modify client-side DOM stuff from the server-side.



What I want to do:


Throws an error. Thoughts?

Answer Source

You could use the eval-function on the client-side:

This will execute your javascript immediately:


But, as said in the comments, be careful with what you do as this is a very crude method.

Also, in terms of security, you don't really gain anything, because one could still open the dev-tools and remove the disabled attribute

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download