For example, our new window fatherpage.htm:
XML-Code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function OpenChildWindow ()
{
Zookeeper open('childpage.htm ');
}
</Script>
<Input type = "text" id = "txtInput"/>
<Input type = "button" value = "OpenChild" onclick = "OpenChildWindow ()"/>
Then, you can use window. opener in childpage.htm to access elements in the parent form:
XML-Code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function SetValue ()
{
Extends extends opener.doc ument. getElementById ('txtinput'). value
= Document. getElementById ('txtinput'). value;
Window. close ();
}
</Script>
<Input type = "text" id = "txtInput"/>
<Input type = "button" value = "SetFather" onclick = "SetValue ()"/>
The secret can be changed:
XML-Code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function OpenChildWindow ()
{
Var child = zookeeper open('childpage.htm ');
Child.doc ument. getElementById ('txtinput'). value
= Document. getElementById ('txtinput'). value;
}
</Script>
<Input type = "text" id = "txtInput"/>
<Input type = "button" value = "OpenChild" onclick = "OpenChildWindow ()"/>
By judging whether the subform reference is null, we can also control that it can only open one subform:
XML-Code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Var child
Function OpenChildWindow ()
{
If (! Child)
Child = zookeeper open('childpage.htm ');
Child.doc ument. getElementById ('txtinput'). value
= Document. getElementById ('txtinput'). value;
}
</Script>
<Input type = "text" id = "txtInput"/>
<Input type = "button" value = "OpenChild" onclick = "OpenChildWindow ()"/>
This is not enough. When the child form is closed, the child variable of the parent form must be cleared; otherwise, the child form cannot be re-opened after it is closed:
XML-Code:
Copy codeThe Code is as follows:
<Body onunload = "Unload ()">
<Script type = "text/javascript">
Function SetValue ()
{
Extends extends opener.doc ument. getElementById ('txtinput'). value
= Document. getElementById ('txtinput'). value;
Window. close ();
}
Function Unload ()
{
Window. opener. child = null;
}
</Script>
<Input type = "text" id = "txtInput"/>
<Input type = "button" value = "SetFather" onclick = "SetValue ()"/>
</Body>