This article illustrates the method of calling the function in the IFRAME frames page in Javscript, this method is very simple, with this method we can achieve the value or modify the value of the IFRAME, the operation is very simple. Share to everyone for your reference. The implementation methods are as follows:
To access the functions within the IFRAME:
Copy Code code as follows:
document.getElementById (' Commentiframe '). contentwindow.haslogined ();
Commentiframe is the ID of the IFRAME.
To be executed inside the window.onload.
Examples are as follows:
1.html
Copy Code code as follows:
<a href= "#" onclick= "window.frames[' frame1 '". Mynext () ">aa</a>
<iframe id= "frame1" src= "2.html" ></iframe>
2.html page
Copy Code code as follows:
<script language= "javascript" type= "Text/javascript" >
function Mynext ()
{
Alert (1);
}
</script>
Click the Test button in 1.htm to invalidate the MyButton button in the 2.htm (IFrame page). It's so simple, hehe. If you want to call the JS function in 2.htm to write this:
Copy Code code as follows:
self.frames[' a '].funtionname (param)
In 1.htm, call the JS function in 2.htm: Iframe2.showinfo ();
Example Description:
Suppose there are 2 pages, index.html and inner.html. One of the index.html has an IFRAME, which is the src of the iframe pointing to inner.html.
All we have to do now is:
1. Call a JS method on the inner.html in index.html
2. Call a JS method on the index.html in inner.html
The implementation code is as follows:
Index.html:
Copy Code code as follows:
<script type= "Text/javascript" >
function ff () {
Alert (">>this is index ' s JS function index.html");
}
</script>
<body>
<div style= "Background:lightblue;" >
This is index page.
<input type= "button" value= "Run index ' s function" onclick= "FF ();"/>
<input type= "button" value= "Run inner page ' s function ' onclick= ' window.frames[' Childpage '].sonff (); '/>
</div>
<iframe id= "Childpage" name= "Childpage" src= "inner.html" width= "100%" frameborder= "0" ></iframe>
</body>
Inner.html:
Copy Code code as follows:
<script type= "Text/javascript" >
function Sonff () {
Alert (">>this is inner page ' s JS function");
}
</script>
<body>
<div style= "Background:lightgreen;" >
This is inner page.
<input type= "button" value= "Run index ' s function" onclick= ' parent.window.ff (); '/>
<input type= "button" value= "Run inner page ' s function" onclick= "SONFF ();"/>
</div>
</body>
I hope this article will help you with your JavaScript based Web programming.