#2997 closed bug (fixed)
$.clone() bugs in IE when $.length>1 and elements don't belong to document
Reported by: | shazam | Owned by: | flesler |
---|---|---|---|
Priority: | minor | Milestone: | 1.3 |
Component: | core | Version: | 1.2.6 |
Keywords: | clone | Cc: | |
Blocked by: | Blocking: |
Description
If you are manipulating elements in a child iframe, the clone method tries to do some manips inserting nodes belonging to child iframe document into main frame document.
The clone method should be replace by this one which uses this.ownerDocument when possible
clone: function( events ) { // Do the clone var ret = this.map(function(){ if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { // IE copies events bound via attachEvent when // using cloneNode. Calling detachEvent on the // clone will also remove the events from the orignal // In order to get around this, we use innerHTML. // Unfortunately, this means some modifications to // attributes in IE that are actually only stored // as properties will not be copied (such as the // the name attribute on an input). var clone = this.cloneNode(true), container = (this.ownerDocument||document).createElement("div"); container.appendChild(clone); return jQuery.clean([container.innerHTML], this.ownerDocument||document)[0]; } else return this.cloneNode(true); });
Attachments (2)
Change History (11)
comment:1 Changed 15 years ago by
comment:2 follow-up: 7 Changed 15 years ago by
Title is wrong and should be '$.clone() bugs in IE'
The clone function is not completely false and only the begining has been written in the post
comment:3 Changed 15 years ago by
need: | Patch → Test Case |
---|---|
Priority: | major → minor |
So, does that cause an error or what ? Could you provide a test case ? a minimalistic html file with the requires html and js to reproduce the problem ? And please detail the error or odd behavior. Thanks.
comment:4 Changed 15 years ago by
Yes this causes an 'invalid argument' error when you manipulate elements in a child iframe.
I took the time to make a complete sample.
I also made a better fix to the problem which is well explained in the sample.
So, this part of the $.clone() function :
var clone = this.cloneNode(true), container = (this.ownerDocument||document).createElement("div"); container.appendChild(clone); return jQuery.clean([container.innerHTML], this.ownerDocument||document)[0];
Should be replaced by :
// As this line is executed only in IE we can use the outerHTML property // and we use this.ownerDocument in the $.clean() function to avoid cross document bug return jQuery.clean([this.outerHTML], this.ownerDocument||document)[0];
Changed 15 years ago by
Attachment: | cloneBug.rar added |
---|
comment:5 Changed 15 years ago by
Owner: | set to flesler |
---|---|
Status: | new → assigned |
Right, clever proposition, could be reduced to:
return jQuery.clean([this.outerHTML], this)[0];
jQuery.clean will handle the rest. I'll assign this to myself and will check this asap. This obviously needs a lot of testing. Will surely be in for the next release if all goes well.
Thanks
comment:6 Changed 15 years ago by
need: | Test Case → Commit |
---|
comment:7 Changed 15 years ago by
Replying to shazam:
Title is wrong and should be '$.clone() bugs in IE'
The clone function is not completely false and only the begining has been written in the post
So do you know the situation about clone a node from child frame to parent window? Regards
Changed 15 years ago by
Attachment: | clone[5790].diff added |
---|
This is the patch, but it breaks many many tests :(
comment:8 Changed 14 years ago by
This works..
var clone = this.cloneNode(true), container = this.ownerDocument.createElement("div"); container.appendChild(clone); return jQuery.clean([container.innerHTML], this)[0];
Title is wrong and should be $.clone() bugs in IE The clone function is not completely false and only the begining has been written in the post