Bug Tracker

Opened 11 years ago

Closed 11 years ago

#4074 closed bug (fixed)

.clone() doesn't respect ownerDocument

Reported by: friedcell Owned by: john
Priority: major Milestone: 1.3.2
Component: core Version: 1.3.1
Keywords: clone iframe Cc:
Blocked by: Blocking:

Description

If you clone an element from a foreign document (not the one you're executing code in), the cloned node will not have the same ownerDocument as the original element. It will instead be owned by the document where the execution happens.

elem.ownerDocument === document > false var clone = $(elem).clone(); clone.ownerDocument === elem.ownerDocument > false (should be true) clone.ownerDocument === document > true (should be false)

There is a simple fix to this - the code in clone() shouldn't use document.createElement but this.ownerDocument and the call to clear should use this for context (currently uses nothing).

Change History (5)

comment:1 Changed 11 years ago by dmethvin

Keywords: clone iframe added
Owner: set to flesler

comment:2 Changed 11 years ago by john

Resolution: fixed
Status: newclosed

This was fixed when the recent IE clone refactoring landed.

comment:3 Changed 11 years ago by doug

Resolution: fixed
Status: closedreopened

Using this.ownerDocument for createElement is a partial fix. The call to clean() also needs the context.

That is,

return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/\s*/, "")], this.ownerDocument)[0];

I've seen the problem when using .wrap("<div></div>").

comment:4 Changed 11 years ago by dmethvin

Owner: changed from flesler to john
Status: reopenednew

I think that was mentioned on one of the tickets for this issue but it got lost. Thanks!

comment:5 Changed 11 years ago by brandon

Resolution: fixed
Status: newclosed

fixed in r6280

Note: See TracTickets for help on using tickets.