For top level windows, the parent property is the same as the self property.
For framed windows the parent will be a Window object.
In the same way that you can walk downwards through the frames hierarchy with a frames[ ... ].frames[ ... ] construct, a parent.parent construct will walk upwards through the hierarchy.
It is important to know where you are so that this is as useful as possible. Relative locations in trees need to have some awareness of the root. If you don't detect this, you might have problems.
Detecting whether you have reached the root can be accomplished by testing whether the parent property of a window refers to the same object as the window itself.
When you reach the top of the tree, the parent property should yield the same value as the self property. This means that the property will equivalent to self for all windows unless they are inside frames. In MSIE, this also means that they are possibly inside an <IFRAME> as well.
Inside a modal dialog window, the parent will be a Dialog object.
Be careful when building tree walking scripts that traverse the window hierarchy. You can reach the top level and continue in an endless loop referring to the parent of an object that is the object itself. You should test to see whether parent = self and then exit your tree walker knowing that you have reached the root node.
See also: | Dialog object, Frame object, Window object, Window.frames[], Window.top |
Prev | Home | Next |
Window.pageYOffset | Up | Window.personalbar |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |