here’s the useful implementation for extracting scripts from text or html code:
String.implement({ extractScripts:function(){ var r, h=this.stripScripts(function(js){ r=js; }); return r; } });
And you would use it like this:
script="some text <script> alert('hi'); </script>".extractScripts(); $exec(script); //says 'hi'