bf4 / controljs

Automatically exported from code.google.com/p/controljs
Apache License 2.0
0 stars 0 forks source link

better CJS.eval #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 stevesou...@gmail.com on 26 Dec 2010 at 5:33

GoogleCodeExporter commented 9 years ago
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 serverhe...@gmail.com on 27 Dec 2010 at 6:07