Some writing about parent-child page data interaction in JS
1.window.frames["Test"].document.getelementbyid (' menu ');
2.//because all functions are stored inside the window object, you can remove the opening window:
3.frames["Test"].document.getelementbyid (' menu ');
4.//in the browser, the frame's Name property is the default equivalent to the Child page's Window object, so you can further abbreviate:
5.test.document.getelementbyid (' menu ');
window.frames["Test"].document.getelementbyid (' menu ');
Because all functions are stored inside the window object, you can remove the opening window:
frames["Test"].document.getelementbyid (' menu ');
In the browser, the frame's Name property is the default equivalent to the Child page's Window object, so you can further abbreviate:
Test.document.getElementById (' menu '); 2.2 The parent page accesses the child page function or object. The function and object of the child page are all in its window object, ditto, the key is to get the object.
Java code
1.//If the child.html defines the SHOWMESG function and needs to be called in the parent, then write
2.window.frames[' Test '].showmesg ();
3.//Shorthand Form
4.TEST.SHOWMESG ();
5.//Similarly, objects are accessed like this
6.alert (Test.person);
If child.html defines the SHOWMESG function and needs to be called in the parent, then write
window.frames[' Test '].showmesg ();
Abbreviated form
TEST.SHOWMESG ();
Similarly, objects are accessed like this
alert (Test.person);
Example
Parent window: a1.html
| The code is as follows |
Copy Code |
| <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" > <title>a.html</title>
<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" > <meta http-equiv= "description" content= "This are my page" > <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "> <script language= "JavaScript" > function Openwin () { window.open ("./a2.html", "_blank", "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no"); } function Setvalues (id,name) { document.getElementById ("CID"). Value = ID; document.getElementById ("CNAME"). Value = name; } </script>
<body> <form name= "Form1" action= "test.html" method= "POST" > Customer ID: <input type= "text" name= "CID" value= "id=" CID ><br> Customer Name <input type= "text" name= "CNAME" value= "id=" CNAME "> <input type= "button" Name= "OK" value= "Please select customer" onclick= "Openwin ();" /> </form> </body>
|
child window: a2.html
| The code is as follows |
Copy Code |
| <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" > <title>a2.html</title> <meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" > <meta http-equiv= "description" content= "This are my page" > <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "> <script language= "JavaScript" > function ViewData (id,name) { Window.opener.setValues (Id,name); Window.opener = null; Window.close (); } </script> <body> <table border= "1" > <tr> <td> Operations </td> <td> Customer id</td> <td> Customer Name </td> </tr>
<tr> <td><input type= "button" value= "select" id= "ss" onclick= "ViewData (' 001 ', ' Shenzhen Huawei ')" ></td> <td>001</td> <td> Shenzhen Huawei </td> </tr> <tr> <td><input type= "button" value= "select" onclick= "ViewData (' 002 ', ' Ufida ')" > </td> <td>002</td> <td> UF software </td> </tr> </table> </body>
|