Side navigation
#14568 closed bug (migrated)
Opened November 22, 2013 01:27PM UTC
Closed October 21, 2014 12:26AM UTC
Problem with the context when loading a script in an iframe
| Reported by: | jjgcastela@gmail.com | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | 1.12/2.2 |
| Component: | ajax | Version: | 2.0.3 |
| Keywords: | Cc: | ||
| Blocked by: | Blocking: |
Description
When you create a script node and append it to a head or a body of an iframe, the code is evaluated in the main window (where the jQuery was loaded) instead of in the window of the iframe.
I have been able to solve it adding the desired 'document' as the second argument of the 'globalEval' function this way:
globalEval: function( code , doc) {
var script,
indirect = eval;
code = jQuery.trim( code );
if ( code ) {
// If the code includes a valid, prologue position
// strict mode pragma, execute code by injecting a
// script tag into the document.
if ((doc && doc != document) || code.indexOf("use strict") === 1 ) {
if(!doc) doc = document;
script = doc.createElement("script");
script.text = code;
doc.head.appendChild( script ).parentNode.removeChild( script );
} else {
// Otherwise, avoid the DOM node creation, insertion
// and removal by using an indirect global eval
indirect( code );
}
}
}
And then in the 'domManip' function, adding this parameter in the call to 'globalEval':
jQuery.globalEval( node.textContent.replace( rcleanScript, "" ), doc );
Attachments (0)
Change History (3)
Changed March 01, 2014 10:43PM UTC by comment:1
Changed April 17, 2014 08:38PM UTC by comment:2
| component: | unfiled → ajax |
|---|---|
| milestone: | None → 1.12/2.2 |
| priority: | undecided → high |
| status: | new → open |
Changed October 21, 2014 12:26AM UTC by comment:3
| resolution: | → migrated |
|---|---|
| status: | open → closed |
Migrated to https://github.com/jquery/jquery/issues/1757
This will be affected by the switch to script tags being contemplated in https://github.com/jquery/jquery/pull/1449 .