Method for javascirpt to realize value transfer between two iframe

  • 2021-07-01 06:17:04
  • OfStack

In this paper, an example is given to describe the method of javascirpt to realize value transfer between two iframe. Share it for your reference, as follows:

index.htm


<body>
 <table border="1" width="100%">
 <tr>
  <td width="100%"><iframe src="iframe1.htm" name="aa"></iframe></td>
 </tr>
 <tr>
  <td width="100%"><iframe src="iframe2.htm" name="bb"></iframe></td>
 </tr>
 </table>
</body>

iframe1.htm


<html>
<title>1</title>
<head>
 <script type="text/JavaScript">
 <!--
 function aa(){
 parent.frames["bb"].document.all["TextBox3"].value = document.getElementById("TextBox1").value;
 parent.frames["bb"].document.all["TextBox4"].value = document.getElementById("TextBox2").value;
 alert(parent.frames["bb"].document.all["TextBox3"].value);
 alert(parent.frames["bb"].document.all["TextBox4"].value);
 }
// --></script>
</head>
 <body>
 <form id="a">
 <input id="TextBox1" type="text" id="TextBox1" value="1"/>
 <input id="TextBox2" type="text" id="TextBox2" value="2"/>
 <input id="T" type="button" value="3333333" onclick="aa();"/>
 </form>
 </body>
</html>

iframe2.htm


<html>
<title>2</title>
<head></head>
 <body>
 <form id="b">
 <input id="TextBox3" type="text" id="TextBox1" value="1231111"/>
 <input id="TextBox4" type="text" id="TextBox2" value="123"/>
 </form>
 </body>
</html>

More readers interested in JavaScript can check the topic of this site: "Summary of JavaScript Value Transfer Operation Skills", "Summary of javascript Coding Operation Skills", "Summary of json Operation Skills in JavaScript", "Summary of JavaScript Switching Special Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Error and Debugging Skills", "Summary of JavaScript Data Structure and Algorithm Skills", "Summary of JavaScript Traversal Algorithm and Skills" and "Summary of JavaScript Mathematical Operation Usage"

I hope this article is helpful to everyone's JavaScript programming.


Related articles: