In two different situations:
The first type: Invoke the parent page JS function in the IFRAME child page:
The child page calls the parent page function just write window.praent on it. For example, to call a () function, you can write:
The code is as follows |
Copy Code |
WINDOW.PRAENT.A (); A () as a method; |
The second type: in the IFRAME Child parent page Call the child page JS function:
This is a little more complicated, we can use:
The code is as follows |
Copy Code |
document.getElementById (' Ifrtest '). contentwindow.b (); |
Note: Ifrtest is the id,b () of the IFRAME frame as the JS function of the sub page. Contentwindow is the specified frame or the Window object where the IFRAME, ie can be omitted
Example
Parent page: index.html (using IFRAME to include subpages child.html)
The code is as follows |
Copy Code |
<script type= "Text/javascript" > <!-- function Toshow (msg) { Alert ("Here is the parent page:" +msg); } --> </script> <body> <iframe background= "Blue" src= "child.html" mce_src= "child.html" ></iframe> </body>
|
Sub-page child.html (invoke parent page Toshow method)
The code is as follows |
Copy Code |
<script type= "Text/javascript" > <!-- function Doparent () { Window.parent.toshow (' Ccccchild '); } --> </script> <body> This are child frame!! <input type= "button" value= "click" onclick= ' doparent () ' ></input> </body>
|
Add: Get elements from the IFRAME child page in the parent page:
var child = document.getelementbyidx_x ("MainFrame"). Contentwindow;//mainframe this ID is the ID of the parent page iframe
child.document;//gets the document object in the child page;