Bug 100457

Summary: copying DOM nodes between documents using JavaScript doesn't work
Product: [Applications] konqueror Reporter: Clifford Wolf <clifford>
Component: khtmlAssignee: Konqueror Developers <konq-bugs>
Status: RESOLVED UNMAINTAINED    
Severity: normal CC: Hinrich.Sager, linux
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: testcase: inner.html
testcase: outer.html (uses inner.html attachment)

Description Clifford Wolf 2005-02-28 17:26:39 UTC
Version:            (using KDE KDE 3.3.2)
Installed from:    Compiled From Sources
Compiler:          gcc 3.4.2 
OS:                Linux

I'm trying to copy a paritial dom tree from an iframe to the parent frame.
In my understanding of js and dom this should work and there are no
problems with mozilla/firefox (see html sources at the end of this bug report).

It seams like this always is a problem when I'm trying to copy something
from one document to another - but it always works fine when I'm just in
one document.

Also, when I'm fetching an XHTML document from a server using the
XMLHttpRequest object I can't copy parts from the DOM tree I recieve to the
document displayed. That also works fine with mozilla/firefox.

I don't get any JavaScript errors on the console. It just fails. By adding
alert() calls to the javasript it can be proven that the JavaScript really
stops executing (instead of just not displaying the new updated page, e.g.).

It's hard to tell as non-insider if this is a KJS or KHTML bug..

--- inner.html ---

<html><body>
<div id="a">This is div A.</div>
</body></html>

--- outer.html ---

<html><body bgcolor="#eeffff">

<iframe name="inner" src="inner.html">
</iframe>

<div id="b">This is div B.</div>

<script><!--

  function doit() {
        var new_node = inner.document.getElementById("a").cloneNode(true);
        document.getElementById("b").parentNode.replaceChild(new_node, document.getElementById("b"));
  }

//--></script>

<form>
<input type="button" onclick="doit()" value="Click!" />
</form>

</body></html>
Comment 1 George Staikos 2005-06-20 06:39:17 UTC
SVN commit 427263 by staikos:

Merge webcore fix for replaceChild()
BUG: 100457
BUG: 72430



 M  +4 -0      ChangeLog  
 M  +87 -8     ecma/kjs_binding.cpp  
 M  +25 -5     ecma/kjs_binding.h  
 M  +34 -25    xml/dom_nodeimpl.cpp  
 M  +2 -0      xml/dom_nodeimpl.h  
Comment 2 George Staikos 2005-06-20 14:57:01 UTC
Fix was reverted since it was an incomplete merge and caused crashes and rendering errors
Comment 3 George Staikos 2005-06-20 14:58:54 UTC
*** Bug 72430 has been marked as a duplicate of this bug. ***
Comment 4 J Appel 2006-09-12 21:18:59 UTC
Is this still an issue with kde 3.5.4?
Comment 5 Maksim Orlovich 2006-09-12 21:25:13 UTC
Nothing relevant has changed, Juergen.

But to reporter: actually, your understanding of what the DOM says is very wrong. In fact, it -requires- doing what KHTML does: raising an exception:

"WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node."

.. and so Mozilla,  just like IE, is breaking the spec here... The -proper- thing to do here is to use importNode. Having said that, this is something which we will eventually change to match the existing practice --- following the spec here would just screw over our users.

Comment 6 Daniel Hahler 2007-12-28 00:01:28 UTC
Created attachment 22721 [details]
testcase: inner.html
Comment 7 Daniel Hahler 2007-12-28 00:04:06 UTC
Created attachment 22722 [details]
testcase: outer.html (uses inner.html attachment)
Comment 8 Maksim Orlovich 2011-01-09 16:36:43 UTC
*** Bug 66781 has been marked as a duplicate of this bug. ***
Comment 9 Justin Zobel 2021-03-21 00:25:32 UTC
Thank you for the bug report.

As this report hasn't seen any changes in 10 years or more, we ask if you can please confirm that the issue still persists.

If this bug is no longer persisting or relevant please change the status to resolved.
Comment 10 Christoph Cullmann 2024-05-06 18:38:34 UTC
Dear user,

KHTML (and KJS) was a long time more or less unmaintained and got removed in KF6.

Please migrate to use a QWebEngine based HTML component.

We will do no further fixes or improvements to the KF5 branches of these components beside important security fixes.

For security issues, please see:

https://kde.org/info/security/

Sorry that we did not fix this issue during the life-time of KHTML.

Greetings
Christoph Cullmann