controljs icon indicating copy to clipboard operation
controljs copied to clipboard

better CJS.eval

Open GoogleCodeExporter opened this issue 9 years ago • 1 comments

Nicholas Zakas recommends this way of evaling JS in the global scope:

var script = document.createElement("script");
script.text = jscodeText;
document.body.appendChild(script);


Original issue reported on code.google.com by [email protected] on 26 Dec 2010 at 5:33

GoogleCodeExporter avatar Mar 16 '15 22:03 GoogleCodeExporter

In firefox <= 3.6 execution of this code will be blocked by any queued scripts 
which are pending download.  This is due to FireFox's serial execution of all 
script elements and, AFAIK, has been changed in FF 4beta.  

This seems to work-around the problem, but only works in FF 3.6
script = document.createElement('script') 
script.async= true;
script.src= "data:text/html," + jscodeText; 


Because data url's may not be supported in IE, it will probably require browser 
sniffing. Here's a sample page: 
http://digital-fulcrum.com/controljs/t/ffasync/

Original comment by [email protected] on 27 Dec 2010 at 6:07

GoogleCodeExporter avatar Mar 16 '15 22:03 GoogleCodeExporter