Java Reference
In-Depth Information
The easiest way to think of the hierarchy of such a frames-based web page is in terms of familial relation-
ships, which can be shown in a family tree. If you represent your frameset like that, it looks something
like the diagram in Figure 8-9.
Top Window
frameMenu
frameMain
frameTop
frameBottom
Figure 8-9
From the diagram you can see that frameBottom, the right-hand frame's bottom frame, has a parent
frame called frameMain, which itself has a parent, the top window. Therefore, if you wanted to access a
function in the top window from the frameBottom window, you would need to access frameBottom's
parent's parent's window object. You know that the window object has the parent property, which is a
reference to the parent window of that window object. So let's use that and create the code to access a
function, for example, called myFunction(), in the top window.
window.parent.parent.myFunction();
Let's break this down. The following code gets you a reference to the parent window object of the win-
dow in which the code is running.
window.parent
The code is in frameBottom, so window.parent will be frameMain. However, you want the top window,
which is frameMain's parent, so you add to the preceding code to make this:
window.parent.parent
Now you have a reference to the top window. Finally, you call myFunction() by adding that to the end
of the expression.
window.parent.parent.myFunction();
What if you want to access the window object of frameMenu from code in frameBottom? Well, you have
most of the code you need already. You saw that window.parent.parent gives you the top window,
so now you want that window's child window object called frameMenu. You can get it in three ways, all
with identical results.
You can use its index in the frames collection property of the window object as follows:
window.parent.parent.frames[0]
Alternatively, you can use its name in the frames collection like this:
window.parent.parent.frames[“frameMenu”]
Search WWH ::




Custom Search