divinci divinci - 1 year ago 166
Javascript Question

Execute JavaScript code stored as a string

How do I execute some JavaScript that is a string?

function ExecuteJavascriptString()
var s = "alert('hello')";
// how do I get a browser to alert('hello')?

Answer Source

With eval("my script here") function.

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