IFRAME cross-page call Function

Source: Internet
Author: User

 

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.