diff options
-rw-r--r-- | src/core.js | 7 | ||||
-rw-r--r-- | src/manipulation.js | 2 | ||||
-rw-r--r-- | test/data/manipulation/scripts-context.html | 18 | ||||
-rw-r--r-- | test/unit/manipulation.js | 11 |
4 files changed, 34 insertions, 4 deletions
diff --git a/src/core.js b/src/core.js index 8e43547ac..9095213eb 100644 --- a/src/core.js +++ b/src/core.js @@ -258,11 +258,12 @@ jQuery.extend( { }, // Evaluates a script in a global context - globalEval: function( code ) { - var script = document.createElement( "script" ); + globalEval: function( code, context ) { + context = context || document; + var script = context.createElement( "script" ); script.text = code; - document.head.appendChild( script ).parentNode.removeChild( script ); + context.head.appendChild( script ).parentNode.removeChild( script ); }, // Convert dashed to camelCase; used by the css and data modules diff --git a/src/manipulation.js b/src/manipulation.js index ceb970cbd..eaf2e0998 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -192,7 +192,7 @@ function domManip( collection, args, callback, ignored ) { jQuery._evalUrl( node.src ); } } else { - jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) ); + jQuery.globalEval( node.textContent.replace( rcleanScript, "" ), doc ); } } } diff --git a/test/data/manipulation/scripts-context.html b/test/data/manipulation/scripts-context.html new file mode 100644 index 000000000..6958453c5 --- /dev/null +++ b/test/data/manipulation/scripts-context.html @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset=utf-8 /> + <title>body</title> + </head> + <body> + <div id="qunit-fixture"></div> + <script src="../../jquery.js"></script> + <script> + window.parent.iframeCallback( + window, + document.body, + "<script>window.scriptTest = true;<\x2fscript>" + ); + </script> + </body> +</html> diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 37da12062..a56956fa1 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2162,6 +2162,17 @@ testIframeWithCallback( } ); +testIframeWithCallback( + "domManip executes scripts in iframes in the iframes' context", + "manipulation/scripts-context.html", + function( frameWindow, bodyElement, html, assert ) { + assert.expect( 2 ); + jQuery( bodyElement ).append( html ); + assert.ok( !window.scriptTest, "script executed in iframe context" ); + assert.ok( frameWindow.scriptTest, "script executed in iframe context" ); + } +); + QUnit.test( "jQuery.clone - no exceptions for object elements #9587", function( assert ) { assert.expect( 1 ); |