Java Reference
In-Depth Information
when the browser has fi nished loading the window, the document inside the window, and all the objects
within the document. It's a very useful place to put initialization code or code that needs to change things
after the page has loaded but before control passes back to the user.
<body onload=”window_onload()”>
This function is defi ned in a script block in the head of the page as follows:
function window_onload()
{
alert(“The name of the upper frame's window object is “ + window.name);
alert(“The location of UpperWindow's parent is “ +
window.parent.location.href);
}
The window_onload() function makes use of two properties of the window object for the frame that
the page is loaded in: its name and parent properties. The name property is self-explanatory — it's the
name you defi ned in the frameset page. In this case, the name is upperWindow.
The second property, the parent property, is very useful. It gives you access to the window object of the
frame's parent. This means you can access all of the parent window object's properties and methods.
Through these, you can access the document within the parent window as well as any other frames
defi ned by the parent. Here, you display a message box giving details of the parent frame's fi le name
or URL by using the href property of the location object (which itself is a property of the window
object).
The code for ch08_examp1_lower.htm is identical to the code for ch08_examp1_upper.htm, but with
different results because you are accessing a different window object. The name of the window object this
time is lowerWindow. However, it shares the same parent window as upperWindow, and so when you
access the parent property of the window object, you get a reference to the same window object as in
upperWindow. The message box demonstrates this by displaying the fi le name/URL or href property,
and this matches the fi le name of the page displayed in the upperWindow frame.
The order of display of messages may vary among different types of browsers and even different operat-
ing systems. This may not be important here, but there will be times when the order in which events fi re
is important and affects how your code works. It's an incompatibility that's worth noting and watching
out for in your own programs.
Coding Between Frames
You've seen that each frame exists as a different window and gets its own window object. In addition,
you saw that you can access the window object of a frameset-defi ning page from any of the frame pages
it specifi es, by using the window object's parent property. When you have a reference to the parent
window's window object, you can access its properties and methods in the same way that you access the
window object of the current page. In addition, you have access to all the JavaScript variables and func-
tions defi ned in that page.
Search WWH ::




Custom Search