Java Reference
In-Depth Information
Finally, you can reference it directly by using its name as you can with any window object:
window.parent.parent.frameMenu
The third method is the easiest unless you don't know the name of a frame and need to access it by its
index value in the frames collection, or are looping through each child frame in turn.
Since window.parent.parent.frameMenu gets you a reference to the window object associated with
frameMenu, to access a function myFunction() or variable myVariable, you would just type one of
these lines:
window.parent.parent.frameMenu.myFunction
or
window.parent.parent.frameMenu.myVariable
What if you want to access not a function or variable in a page within a frame, but a control on a form
or even the links on that page? Well, let's imagine you want to access, from the frameBottom page, a
control named myControl, on a form called myForm in the frameMenu page.
You found that window.parent.parent.frameMenu gives you the reference to frameMenu's window
object from frameBottom, but how do you reference a form there?
Basically, it's the same as how you access a form from the inside of the same page as the script, except
that you need to reference not the window object of that page but the window object of frameMenu, the
page you're interested in.
Normally you write document.myForm.myControl.value, with window being assumed since it is the
global object. Strictly speaking, it's window.document.myForm.myControl.value.
Now that you're accessing another window, you just reference the window you want and then use
the same code. So you need this code if you want to access the value property of myControl from
frameBottom:
window.parent.parent.frameMenu.document.myForm.myControl.value
As you can see, references to other frames can get pretty long, and in this situation it's a very good idea
to store the reference in a variable. For example, if you are accessing myForm a number of times, you
could write this:
var myFormRef = window.parent.parent.frameMenu.document.myForm;
Having done that, you can now write
myFormRef.myControl.value;
rather than
window.parent.parent.frameMenu.document.myForm.myControl.value;
Search WWH ::




Custom Search