This article example describes the method of calling the parent page in js by iframe. Share it for your reference. The specific implementation method is as follows:
The method of child page calling the parent page is easy to implement in js. We just need to add a function to the main page, and then use window.parent. method() on the subpage to achieve it
For example, if you call the a() function, you will write it as:
The code copy is as follows: window.parent.a();
But I found that this method is invalid in the chrome browser
Copy the code as follows: //Call the function in the parent page
<script>
function dey() {
var cards_frame=document.frames("card-iframe"); //card-iframe is the name of the iframe
cards_frame.checkedCard() //Call the method defined in the iframe and pass the value of the embedded page to the parent page
}
</script>
2) Call the method defined by the parent page in the iframe
The code copy is as follows: function alert_window(picurl,h_id)
{
document.parentWindow.parent.msg(picurl,h_id);
}
//msg() is a function defined by the parent window.
card-iframe is the id of the iframe framework, and b() is the subpage js function. The contentWindow property is the window object where the specified frame or iframe is located, and can be omitted in IE.
I hope this article will be helpful to everyone's JavaScript programming.