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.