document.createElement doesn't work across frames (Re: Javascript cross-frame scripting problem)

Koos Vriezen koos.vriezen at xs4all.nl
Tue May 3 15:46:25 BST 2005


On Mon, May 02, 2005 at 08:45:01PM +0200, Martijn Klingens wrote:
> On Monday 02 May 2005 20:32, Martijn Klingens wrote:
> > On Monday 02 May 2005 20:14, Koos Vriezen wrote:
> > > Maybe IE timers start ticking after an onLoad or so :-):-)
> >
> > That might actually not be a bad idea :):)
> 
> It doesn't make a difference though, if I add a timeout of a couple of seconds 
> I still get the problem.
> 
> I did find the real problem cause though: the element is created in another 
> document and apparently IE reparents it to the new frame and KHTML does not.
> 
> Replace 
> 
>     element = document.createElement( "HR" );
> 
> with
> 
>     element = top.frames['frame2'].document.createElement( 'HR' );
> 
> and the testcase works. Can someone confirm that the original code works in IE 
> and that the extended version is only needed in KHTML/KJS?

With IE 6.0.2800.1106 and wine/testing uptodate 0.0.20050310-1.1 it also
fails. Btw, I think if you change xml/dom_nodeimpl.cpp:767 to something
like
  if (newChild->getDocument() != getDocument()) {
    if (newChild->getDocument())
      newChild->getDocument()->deref();
    newChild->document = getDocument();
    if (document)
      document->ref();
  }
you might bypass it w/o crashing .. unless it has only one child ..

Koos




More information about the kfm-devel mailing list