This article describes how to Javscript call iframe page frame function can be achieved by value or modify the value between iframe, is a very useful skill, need friends can refer to the following
This paper describes examples of method invocation framework iframe page function in Javscript, calling this method is actually very simple, with this method we can pass values or modify values between iframe can be achieved, are very simple to operate. Share to you for your reference. Specific method is as follows:
Access functions inside the iframe:
commentIframe is the id iframe.
To perform inside the window.onload
Examples are as follows:
1.html
<iframe id="frame1" src="2.html" ></iframe>
2.html page
function MyNext()
{
alert(1);
}
</script>
Click the test button 1.htm, you can make 2.htm (iframe page) button in mybutton failure. It's that simple, huh, huh. If you are calling 2.htm function in JS wrote:
Call 1.htm in 2.htm in JS function: iframe2.showInfo ();
Examples:
Suppose there are two pages, index.html and inner.html. Index.html which there is a iframe, the iframe's src point inner.html.
We now have to do is:
1. call a method on the inner.html js in the index.html
2. js call a method on the index.html in inner.html
Codes are as follows:
index.html:
<head>
<script type="text/javascript">
function ff(){
alert(">>this is index's js function index.html");
}
</script>
</head>
<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>
</html>
inner.html:
<head>
<script type="text/javascript">
function sonff(){
alert(">>this is inner page's js function");
}
</script>
</head>
<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>
</html>
In this paper, we want the design to help javascript-based web application.