23. juni 2000 - 13:41
Der er
3 kommentarer og
1 løsning
Kontrollér et vindue fra et andet
Jeg har en lille javascript-funktion, der åbner et NYT vindue. Hvordan kan jeg styrer det GAMLE vindue fra det NYE vindue ..(indviklet forklaring). Det der er mit mål, er at lave en refresh på det GAMLE vindues target:top
Jeg håber at der nogen der forstår mig :o)!!!!
-QUOTE-
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>
15. august 2000 - 11:34
#4
Det er pæcis noget af det jeg søger. Men kan alle vinduer snakke sammen hvis de kender hinandens navne, eller kan man kun snakke sammen med et popup vindue?