Skip to main content

Bug Tracker

Side navigation

#1419 closed bug (fixed)

Opened July 23, 2007 04:23PM UTC

Closed December 05, 2007 05:05AM UTC

Last modified March 15, 2012 04:25PM UTC

Can't modify XML/Iframe documents in IE

Reported by: john Owned by: john
Priority: major Milestone: 1.2.2
Component: core Version: 1.1.3
Keywords: Cc:
Blocked by: Blocking:
Description

Two separate reports of this occurring:

$(document).ready(function(){
       var fred="<hi></hi>";
       console.log(fred);
       // Push through XML processor
       xml = loadXML(fred);

       var b = $("hi:first", xml);
       var node = $("<div class='group' >xxx</div>");
       node.appendTo(b);

});


I'm having a similar problem in IE. However, my code looks like this

(using your syntax for creating the XML document):

var hiNode = $("hi", xml);
hiNode.text("foo");

When I run this in Firefox, the hi node in the XML document gets a

text node with a value of "foo" appended to it. However, I get a type

mismatch error in IE.

I can use the .text() function to retrieve text nodes from XML

documents - can I also use it to set text nodes?

Attachments (0)
Change History (6)

Changed July 23, 2007 04:24PM UTC by john comment:1

description: Two separate reports of this occurring: \ \ {{{ \ (document).ready(function(){ \ var fred="<hi></hi>"; \ console.log(fred); \ // Push through XML processor \ xml = loadXML(fred); \ \ var b = $("hi:first", xml); \ var node = $("<div class='group' >xxx</div>"); \ node.appendTo(b); \ \ }); \ }}} \ \ ---- \ \ I'm having a similar problem in IE. However, my code looks like this \ (using your syntax for creating the XML document): \ \ {{{ \ var hiNode = $("hi", xml); \ hiNode.text("foo"); \ }}} \ \ When I run this in Firefox, the hi node in the XML document gets a \ text node with a value of "foo" appended to it. However, I get a type \ mismatch error in IE. \ \ I can use the .text() function to retrieve text nodes from XML \ documents - can I also use it to set text nodes?Two separate reports of this occurring: \ \ {{{ \ $(document).ready(function(){ \ var fred="<hi></hi>"; \ console.log(fred); \ // Push through XML processor \ xml = loadXML(fred); \ \ var b = $("hi:first", xml); \ var node = $("<div class='group' >xxx</div>"); \ node.appendTo(b); \ \ }); \ }}} \ \ ---- \ \ I'm having a similar problem in IE. However, my code looks like this \ (using your syntax for creating the XML document): \ \ {{{ \ var hiNode = $("hi", xml); \ hiNode.text("foo"); \ }}} \ \ When I run this in Firefox, the hi node in the XML document gets a \ text node with a value of "foo" appended to it. However, I get a type \ mismatch error in IE. \ \ I can use the .text() function to retrieve text nodes from XML \ documents - can I also use it to set text nodes?

Changed July 23, 2007 06:52PM UTC by john comment:2

summary: Can't modify XML documents in IECan't modify XML/Iframe documents in IE

Some relevant bugs:

#968: $('<tag>') needs optional document parameter to ease cross-frame DOM wrangling

#1264: Cross-frame DOM manipulation

Changed November 27, 2007 04:42PM UTC by cdivilly comment:3

I worked around this problem by patching jquery-1.2.1.js as follows:

--- jquery-1.2.1.js	
+++ jquery-1.2.1.js	
@@ -151,8 +151,10 @@
 	},
 
 	text: function(e) {
-		if ( typeof e != "object" && e != null )
-			return this.empty().append( document.createTextNode( e ) );
+		if ( typeof e != "object" && e != null ) {
+		    d = this[0].ownerDocument || document;
+			return this.empty().append( d.createTextNode( e ) );
+		}
 
 		var t = "";
 		jQuery.each( e || this, function(){

The existing code uses the page's DOM to create the text node and then attempts to append the text node to the XML document's DOM. IE does not allow adding a node from one DOM into another. The above patch checks if the current element has an ownerDocument and if so uses that to create the text node instead. Other places where a similar fix might be required, lines: 398 and 2261

Changed December 05, 2007 05:05AM UTC by davidserduke comment:4

milestone: 1.1.41.2.2
resolution: → fixed
status: newclosed

Fixed in [4031] and [4029]. Thanks cdivilly for the patch which I only optimized slightly.

Changed May 10, 2011 03:11PM UTC by anonymous comment:5

The following code sample may be helpful to others who reach this page who are having the problem with the fact that IE does not allow adding a node from one DOM into another.

create a pop up window

PopUp = window.open('', 'MyPopUp', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=800,height=600,left = 340,top = 112');

create a div element within the document of the pop up window

var item_div = PopUp.document.createElement('div');

make a copy of it as a Jquery object on the document of the main page

(Note: the pop up does not have the Jquery js file referenced).

Use jquery to manipulate the item.

var jq_item_div = $(item_div).addClass('item_div').html("Hello World");

return the jquery element into the pop up element

item_div = jq_item_div;

//append the item to the pop up document body

$(PopUp.document.body).append(item_div);

Changed May 10, 2011 03:13PM UTC by anonymous comment:6

The following code sample may be helpful to others who reach this page who are having the problem with the fact that IE does not allow adding a node from one DOM into another.


//create a pop up window 
PopUp = window.open(, 'MyPopUp', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=800,height=600,left = 340,top = 112'); 

//create a div element within the document of the pop up window 
var item_div = PopUp.document.createElement('div');
 
//make a copy of it as a Jquery object on the document of the main page 
//(Note: the pop up does not have the Jquery js file referenced). 
//Use JQuery to manipulate the item. 
var jq_item_div = $(item_div).addClass('item_div').html("Hello World");

//return the jquery element into the pop up element 
item_div = jq_item_div; 

//append the item to the pop up document body 
$(PopUp.document.body).append(item_div);