Home > Web Front-end > JS Tutorial > How to call parent page from iframe in js

How to call parent page from iframe in js

高洛峰
Release: 2016-12-24 16:56:38
Original
1416 people have browsed it

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();
Copy after login

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>
Copy after login

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()为父窗口定义的函数.
Copy after login

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!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template