A fix for bug #1443, where globalEval occurred asynchronously in Safari 2, provided...
[jquery.git] / src / core.js
index 3b0c465..0cf0444 100644 (file)
@@ -564,15 +564,19 @@ jQuery.extend({
                data = jQuery.trim( data );
 
                if ( data ) {
-                       if ( window.execScript )
-                               window.execScript( data );
-
-                       else if ( jQuery.browser.safari )
-                               // safari doesn't provide a synchronous global eval
-                               window.setTimeout( data, 0 );
-
+                       // Inspired by code by Andrea Giammarchi
+                       // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
+                       var head = document.getElementsByTagName("head")[0] || document.documentElement,
+                               script = document.createElement("script");
+
+                       script.type = "text/javascript";
+                       if ( jQuery.browser.msie )
+                               script.text = data;
                        else
-                               eval.call( window, data );
+                               script.appendChild( document.createTextNode( data ) );
+
+                       head.appendChild( script );
+                       head.removeChild( script );
                }
        },