Bug Tracker

Ticket #1419 (closed bug: fixed)

Opened 1 year ago

Last modified 10 months ago

Can't modify XML/Iframe documents in IE

Reported by: john Assigned to: john
Type: bug Priority: major
Milestone: 1.2.2 Component: core
Version: 1.1.3 Keywords:
Cc: Needs: Review

Description (last modified by john) (diff)

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

Change History

Changed 1 year ago by john

  • description changed from 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? to 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 1 year ago by john

  • summary changed from Can't modify XML documents in IE to Can'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 11 months ago by cdivilly

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 10 months ago by davidserduke

  • status changed from new to closed
  • resolution set to fixed
  • milestone changed from 1.1.4 to 1.2.2

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

Note: See TracTickets for help on using tickets.