The method of using child pages in the js parent page

  • 2020-11-25 07:09:23
  • OfStack

iframe is a very common html element. How to write the method of using child pages in the parent page? Here is a brief introduction.
1. Parent page code


<html>
<head>
<meta charset=" gb2312">
<title> The parent page </title>
<script type="text/javascript">
function parentFunction() 
{
 alert('function in parent');
}
function callChild() 
{
 child.window.childFunction();
 /*
  child  for iframe the name Attribute values, 
   Can't for id Because, in FireFox Under the id Can't get iframe object 
 */
}
</script>
</head>
<body>
 <iframe name="child" src="./child.html" ></iframe>
</body>
</html>

2. Code in iframe


<html>
<head>
<meta charset="gb2312">
<title>iframe code </title>
<script type="text/javascript">
function childFunction() 
{
 alert('function in child');
}
function callParent() 
{
 parent.parentFunction();
}
</script>
</head>
<body>
</body>
</html>

The above two code can be in the parent page and child page face each other's functions to call each other, relatively simple, not introduced.
I hope this article has been helpful in learning javascript programming.


Related articles: