Javascript/Jscript implements the mutual reference problem of parent-child form
Recently, many netizens have asked questions about how to use javascipt to implement the function reference of pop-up forms and parent forms.
I have had some experience in this regard in my previous use, and I hope to share it with you. I hope it will be helpful to netizens in need.
This article mainly focuses on examples, with all source code attached to the article.
The key to implementing parent form and child form reference lies in the following points:
(1). The function return value is the reference handle to the pop-up subform.
(2) Get the parent form reference handle. This is the key to function implementation, and it is very simple to say.
Returns the form's parent form.
(3) Form references implemented by self, window, parent, top, etc. are implemented for frames (frame/frameset), and have little to do with this article. If you use parent, you cannot get the parent form that pops up.
This article only provides a simple analysis and explanation for the references between forms. The source code only provides a simple demonstration, which is very incomplete. If used, please add corresponding error checking and other functions.
<HTML>
<HEAD>
<TITLE>Welcome to ZosaTapo's WebSite:::::::::Powered By ZosaTapo</TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var child=null;
function testP(){
alert("Message in parent window!");
}
function openwindow(){
if(child==null){
child=("");
}
}
function callmethod(){
if(child!=null){
();
}
}
function closewindow(){
if(child!=null){
();
child=null;
}
}
//-->
</SCRIPT>
<style type="text/css">
A:hover{color:#0000FF;text-decoration:underline}
BODY{color:#FFFFFF;font-family:Courier New, Courier, mono}
</style>
</HEAD>
<BODY bgcolor="#000000">
<!--Title content bengin-->
<p align=center ><font size=6 color='#6699cc'><b>Welcome To ZosaTapo Castle</b></font></p>
<!--Body content bengin-->
<b>Watch text Changing:</b><br/>
<INPUT TYPE="text" value="changed by child"><br/><br/>
<b>Open child Window:</b><br/>
<input type="button" value="Open Child Window" onclick="openwindow();"><br/><br/>
<b>Call child Method:</b><br/>
<input type="button" value="Call Child Method" onclick="callmethod();"><br/><br/>
<b>Close child Window:</b><br/>
<input type="button" value="Close Child Window" onclick="closewindow();"><br/><br/>
<!--Footer content begin-->
<hr width=100%>
<p align=center >Powered By <a href="mailto:dertyang@">Zosatapo</a>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>Welcome to ZosaTapo's WebSite:::::::::Powered By ZosaTapo</TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var parwindow=null;
parwindow=;
function testC(){
alert("Message in child window!");
}
function changetext(){
if(parwindow!=null){
("author").value="zosatapo";
}
}
function callmethod(){
if(parwindow!=null){
();
}
}
function closewindow(){
if(parwindow!=null){
();
parwindow=null;
}
}
//-->
</SCRIPT>
<style type="text/css">
A:hover{color:#0000FF;text-decoration:underline}
BODY{color:#FFFFFF;font-family:Courier New, Courier, mono}
</style>
</HEAD>
<BODY bgcolor="#000000">
<!--Title content bengin-->
<p align=center ><font size=6 color='#6699cc'><b>Welcome To ZosaTapo Castle</b></font></p>
<!--Body content bengin-->
<b>Change parent Text:</b><br/>
<input type="button" value="Change parent Text" onclick="changetext();"><br/><br/>
<b>Call parent Method:</b><br/>
<input type="button" value="Call Parent Method" onclick="callmethod();"><br/><br/>
<b>Close parent Window:</b><br/>
<input type="button" value="Close Parent Window" onclick="closewindow();"><br/><br/>
Previous page1234567891011121314151617181920Next pageRead the full text