aboutsummaryrefslogtreecommitdiffstats
path: root/src/core.js
diff options
context:
space:
mode:
authorjaubourg <j@ubourg.net>2011-04-07 06:47:15 +0200
committerjaubourg <j@ubourg.net>2011-04-07 06:47:15 +0200
commitf3c6077da02f080f09d73ec4d8a8029f76654c2b (patch)
treee1a24390af25e0dd8fcd07ed796bd16250747d31 /src/core.js
parent4552d135f404b78f4fa1494a3de2911b2e2e4773 (diff)
downloadjquery-f3c6077da02f080f09d73ec4d8a8029f76654c2b.tar.gz
jquery-f3c6077da02f080f09d73ec4d8a8029f76654c2b.zip
Rewrite of globalEval. Uses window.execScript or window.eval with a trick to ensure proper context. Unit tests added.
Diffstat (limited to 'src/core.js')
-rw-r--r--src/core.js27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/core.js b/src/core.js
index a893fc9b3..7f63012a3 100644
--- a/src/core.js
+++ b/src/core.js
@@ -561,24 +561,17 @@ jQuery.extend({
noop: function() {},
- // Evalulates a script in a global context
+ // Evaluates a script in a global context
+ // Workarounds based on findings by Jim Driscoll
+ // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
globalEval: function( data ) {
- if ( data && rnotwhite.test(data) ) {
- // Inspired by code by Andrea Giammarchi
- // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
- var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement,
- script = document.createElement( "script" );
-
- if ( jQuery.support.scriptEval() ) {
- script.appendChild( document.createTextNode( data ) );
- } else {
- script.text = data;
- }
-
- // Use insertBefore instead of appendChild to circumvent an IE6 bug.
- // This arises when a base node is used (#2709).
- head.insertBefore( script, head.firstChild );
- head.removeChild( script );
+ if ( data && rnotwhite.test( data ) ) {
+ // We use execScript on Internet Explorer
+ // We use an anonymous function so that context is window
+ // rather than jQuery in Firefox
+ ( window.execScript || function( data ) {
+ window[ "eval" ].call( window, data );
+ } )( data );
}
},