The example in this article describes the method of calling the parent page from iframe in js. Share it with everyone for your reference. The specific implementation method is as follows:
The method of calling the parent page from the sub-page is easy to implement in js. We only need to add a function to the main page, and then use the window.parent.method() on the sub-page to achieve it
For example, when calling the a() function, it is written as:
window.parent.a();
But I found it in the chrome browser This method is invalid
//在父页面中调用该函数 <script> function dey() { var cards_frame=document.frames("card-iframe"); //card-iframe为iframe的名字 cards_frame.checkedCard() //调用iframe中定义的方法,把内嵌页面的值传到父页面 } </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()为父窗口定义的函数.
card-iframe is the id of the iframe frame, and b() is the js function of the child page. The contentWindow attribute is the window object where the specified frame or iframe is located, and can be omitted under IE.
I hope this article will be helpful to everyone’s JavaScript programming design.
For more related articles on how to call the parent page from an iframe in js, please pay attention to the PHP Chinese website!