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

How to call parent page from iframe in js_javascript skills

WBOY
Release: 2016-05-16 16:32:31
Original
1928 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 for a child page to call the parent 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 would be written as:

Copy code The code is as follows:
window.parent.a();

But I found that this method is invalid in the chrome browser

Copy codeThe code is as follows:
//Call this function in the parent page

<script><br> function dey() {<br> var cards_frame=document.frames("card-iframe"); //card-iframe is the name of iframe <br> cards_frame.checkedCard() //Call the method defined in the iframe to pass the value of the embedded page to the parent page <br> }<br> </script>


2) Call the method defined by the parent page in the iframe

Copy code The code 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 frame, and b() is the sub-page js function. 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.

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