JS to implement the method of cross-page call function of IFRAME _javascript skill

Source: Internet
Author: User

The example of this paper describes the method of JS to implement the cross page call function of the IFRAME. Share to everyone for your reference. The implementation methods are as follows:

The problem with the project is that the page introduces an IFRAME and requires the parent page function to call the child page function or the child page. For example, there are now two pages parent.html and child.html. The parent.html contains an IFRAME and the IFRAME points to child.html. Now you need to call a JS method of child.html/parent.html in parent.html/child.html.

The specific code implementation is as follows:

Parent.html Parent page:

Copy Code code as follows:
<script type= "Text/javascript" >
function Parent_click () {
Alert ("From parent page");
}
</script>
<body>
<input type= "button" value= "Call this page function" onclick= "Parent_click ();"/>
<input type= "button" value= "Call child page function" onclick= ' window.frames["Childpage"].child_click (); '/>
<iframe id= "Childpage" name= "Childpage" src= "inner.html" width= "100%" frameborder= "0" ></iframe>
</body>

child.html Child page:

Copy Code code as follows:
<script type= "Text/javascript" >
function Child_click () {
Alert ("Called Child page Function");
}
</script>
<body>
<input type= "button" value= "Call parent page function" onclick= ' Parent.window.parent_click (); '/>
<input type= "button" value= "Call this page function" onclick= "Child_click ();"/>
</body>

I hope this article will help you with your JavaScript based Web programming.

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.