The iframe in js calls the method of the parent page

  • 2020-03-30 04:13:00
  • OfStack

This article illustrates how an iframe in js calls the parent page. Share with you for your reference. The specific implementation method is as follows:

The method by which the child page calls the parent page is easy to implement in js. All we need to do is add a function to the main page and then implement it on the child page using the window.parent method ()

For example, if I call the function a(), I will write:

window.parent.a();

However, I found that this method did not work in chrome

//This function is called in the parent page
<script>
function dey() {
var cards_frame=document.frames("card-iframe");    //Card-iframe is the name of the iframe & NBSP;           < br / > 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

function alert_window(picurl,h_id) 
{
document.parentWindow.parent.msg(picurl,h_id);
}
//msg() Function defined for the parent window .

Card-iframe is the id of the iframe frame, and b() is the js function of the child page. The contentWindow property is the window object where the specified frame or iframe resides, which can be omitted from IE.


Related articles: