15. august 2000 - 10:32
#2
Interrogation
With frames in a frameset its fairly straight forward to access the parent frame or the child frame, all you need to do is remember the object hierarchy. For example, the following frameset:
<FRAMESET COS=\"50%,50%>
<FRAME SRC=\"one.htm\" NAME=\"left\">
<FRAME SRC=\"two.htm\" NAME=\"right\">
</FRAMESET>
Produces the following structure:
Parent Frame
|
+----+----+
| |
one.htm two.htm
To access the parent frame from one.htm, use simply use: alert(parent.location.href), which will highlight the location of the parent frame, and similarily, to perform the reverse alert(window.one.location.href) will highlight the location of the left frame from the parent frame, and alert(parent.two.location.href) will highlight the location of the right frame from the left frame.
Once you\'ve established this simple object syntax, you can use it to read and write almost any property of any other window within the frameset.
However, when you\'ve opened a new window, the window does not form part of a frameset -- therefore a new means of accessing the new window from the opener (i.e., the window that opens the new window) is required and vice versa.
Well, accessing the new window is straight forward enough, you just use the window name as shown in the previous example. Modern browsers also include a means of accessing the opener window. Funny enough, by providing an opener property, e.g., window.opener, which will reference the window, if any, that opened the current window. For example alert(window.opener.location.href) will highlight the location of the current window\'s opener.
Unfortunately, the opener property was not made available in older browsers -- it was introduced in Nav3 -- but, we are able to create our own window properties/variables at any time:
<SCRIPT LANGUAGE=\"JavaScript\">
<!--
myWindow10 = window.open(\'blank.htm\',\'myExample10\',\'width=200,height=200\');
if (newWindow10.opener == null)
newWindow10.opener = self;
//-->
</SCRIPT>