Java Reference
In-Depth Information
objects contained within frameMain, using window.parent.frameMain.frameTop or window.parent
.frameMain.frameBottom.
Now that you have a reference to the window object of the frame in which you want to navigate, you
can go ahead and change its location.href property to the value of the selected drop-down list item,
causing the frame to load that page.
windowobject.location.href =
choosePage.options[choosePage.selectedIndex].value;
return true;
}
As you saw before, ch08_examp3_main.htm is simply a frameset-defi ning page for frameTop and
frameBottom. Let's now look at the pages you're actually loading into frameTop and frameBottom.
Because they are all the same, you'll look only at ch08_examp3_a.htm.
Let's start by looking at the top script block. This contains two functions, btnShowVisited_onclick()
and setFrameAndPageControls() . You saw the function btnShowVisited_onclick() in the previ-
ous example.
function btnShowVisited_onclick()
{
document.form1.txtaPagesVisited.value = window.top.returnPagesVisited();
}
However, because the frameset layout has changed, you do need to change the code. Whereas previously
the returnPagesVisited() function was in the parent window, it's now moved to the top window. As
you can see, all you need to do is change the reference from window.parent.returnPagesVisited();
to window.top.returnPagesVisited();.
As it happens, in the previous example the parent window was also the top window, so if you had
written your code in this way in the fi rst place, there would have been no need for changes here. It's
often quite a good idea to keep all your general functions in the top frameset page. That way all your
references can be window.top , even if the frameset layout is later changed.
The new function in this page is setFrameAndPageControls(), which is connected to the onclick
event handler of the links defi ned lower down on the page. This function's purpose is to make sure that if
the user navigates to a different page using the links rather than the controls in the frameMenu window,
those controls will be updated to refl ect what the user has done.
The fi rst thing you do is set the formobject variable to reference the form1 in the frameMenu page, as
follows:
function setFrameAndPageControls(linkIndex)
{
var formobject = window.parent.parent.frameMenu.document.form1;
Let's break this down.
window.parent
gets you a reference to the frameMain window object. Moving up the hierarchy, you use the following
code to get a reference to the window object of the top window:
window.parent.parent
Search WWH ::




Custom Search