In js, iframe calls the parent PAGE method, and jsiframe calls the page

Source: Internet
Author: User

In js, iframe calls the parent PAGE method, and jsiframe calls the page

This example describes how to use iframe to call the parent page in js. Share it with you for your reference. The specific implementation method is as follows:

The method for calling the parent page on a child page is easily implemented in js. We only need to add a function on the home page, and then use window. parent. Method () on the sub-page to implement

For example, if the () function is called, it is written:

Copy codeThe Code is as follows: window. parent. ();
However, I found that this method is invalid in chrome.

Copy codeThe Code is as follows: // call this function on the parent page

<Script>
Function dey (){
Var cards_frame = document. frames ("card-iframe"); // card-iframe is the name of iframe
Cards_frame.checkedCard () // call the method defined in iframe to pass the embedded page value to the parent page
}
</Script>
2) Call the method defined by the parent page in iframe

Copy codeThe Code is as follows: function alert_window (picurl, h_id)
{
Document. parentWindow. parent. msg (picurl, h_id );
}
// Msg () Is the function defined in the parent window.
Card-iframe is the id of the iframe framework, and B () is a subpage js function. The contentWindow attribute is the window object of the specified frame or iframe, which can be omitted in IE.

I hope this article will help you design javascript programs.


How does the parent window obtain the JS method in the IFrame of the child window?

Set the ID for iframe
Document. getElementById ('iframeid'). contentWindow. abc ();
Abc () is a subpage function.

Why cannot I call the iframe page on the js parent page?

If iframe is not a cross-origin access, js can call the js function in the subpage on the parent page.

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.