This article describes the method of implementing iframe cross-page calling function by js. Share it for your reference. The specific implementation method is as follows:
In projects, you will inevitably encounter such a problem. The page introduces an IFrame and requires the parent page to call the child page function or the child page needs to call the parent page function. For example: There are now two pages parent.html and child.html. where parent.html contains IFrame and IFrame points to child.html. Now you need to call a js method of child.html/parent.html in parent.html/child.html.
The specific code implementation is as follows:
parent.html parent page:
Copy the code as follows: <html>
<head>
<script type="text/javascript">
function parent_click(){
alert("from parent page");
}
</script>
</head>
<body>
<input type="button" value="Calling this page function" onclick="parent_click();" />
<input type="button" value="Calling child page function" onclick='window.frames["childPage"].child_click();' />
<iframe id="childPage" name="childPage" src="inner.html" frameborder="0"></iframe>
</body>
</html>
child.html subpage:
Copy the code as follows: <html>
<head>
<script type="text/javascript">
function child_click(){
alert("Called subpage function");
}
</script>
</head>
<body>
<input type="button" value="Calling parent page function" onclick='parent.window.parent_click();' />
<input type="button" value="Calling this page function" onclick="child_click();" />
</body>
</html>
I hope that the description in this article will be helpful to everyone's web programming based on javascript.