In the project, it is inevitable that IFRAME is introduced to the page and the parent page needs to call the child page function or the child page needs to call the parent page function. For example, there are two pages: parent.htmland child.html. In parent.html, iframeand iframeindicate to child.html. Now, you can use a js method of child.html/parent.html in parent.html/child.html.
The Code is as follows:
Parent.html
<HTML>
<Head>
<SCRIPT type = "text/JavaScript">
Function parent_click (){
Alert ("from parent page ");
}
</SCRIPT>
</Head>
<Body>
<Input type = "button" value = "Call the function" onclick = "parent_click ();"/>
<Input type = "button" value = "Call the subpage function" onclick = 'window. Frames ["childpage"]. child_click (); '/>
<IFRAME id = "childpage" name = "childpage" src = "inner.html" width = "100%" frameborder = "0"> </iframe>
</Body>
</Html>
Child.html
<HTML>
<Head>
<SCRIPT type = "text/JavaScript">
Function child_click (){
Alert ("called subpage functions ");
}
</SCRIPT>
</Head>
<Body>
<Input type = "button" value = "Call the parent page function" onclick = 'parent. Window. parent_click (); '/>
<Input type = "button" value = "Call the function on this page" onclick = "child_click ();"/>
</Body>
</Html>
Http://blog.csdn.net/qingfeilee/article/details/7280171