self.parent vs. parent?

Jason Keirstead jason at keirstead.org
Wed Mar 9 14:41:20 GMT 2005


I have just realized, after some experimentation, that the reason one of my 
JavaScripts does not work in KHTML, is that 'parent' in my javascript context 
is not referring to the parent frame of the window.

The scenario is simmilar to the following:

- Take any DOM node

	var node = document.createElement("DIV");
	node.innerHTML = "Test";
	document.body.appendChild( node );

 - The dom node is assigned a property called 'parent' (for other scripting I 
won't go into here):

	node.parent = document.body;

... and an onclick handler, that will navigate another frame:

	node.onclick = function () {
		parent.rightPane.location = 'someotherpage.html';
	}

The result - 'parent' is pointing to the document body, rather than the 
'window.parent' property, as one would expect.

What seems to be happening is that KHTML is using the event source as the 
scripting context, rather than the window object. This is different behaviour 
from other browsers ( Gecko,  IE ), where the context is *not* passed into 
the event handler.

So.. the question is - is this on purpose? If it is, is it going to remain 
consistant? (need to know in order to write work-arounds for KHTML).

-- 
If you wait by the river long enough, eventually
you will see the bodies of all your enemies float by.
    - Sun Tzu




More information about the kfm-devel mailing list