Home > Web Front-end > JS Tutorial > body text

A brief introduction to the mutual calling and value-passing methods between parent iframe and child iframe in jQuery

不言
Release: 2018-08-15 10:23:03
Original
4298 people have browsed it

This article brings you a brief introduction to the mutual calling and value-passing methods between parent iframe and child iframe in jQuery. It has certain reference value. Friends in need can refer to it. I hope it will be useful to you. Helps.

iframe in the parent page: as follows

<iframe name="sunPage" id="sunPage" src="sun.html" width="300px" height="auto"></iframe>;
Copy after login

1. The parent iframe calls the method of the child iframe

    $("#sunPage")[0].contentWindow.sunMethod();
Copy after login

The contentWindow object can obtain the window object of the child iframe and is compatible All browsers.
sunMethod() This is the method name in the sub-iframe.

If the iframe ID is not known, for example, use the open method of jbox to open an ifram .You can find the iframe node with the help of jquery's find method.

Such as:

$(selector).find("iframe")[0].contentWondow.sunMethod();
Copy after login

2. Parent iframe modifies the data in the child iframe tag: such as modifying the input value in the child iframe.

      $(&#39;#sunPage&#39;).contents().find("#sunP").text("dsssssdd");
Copy after login

jQuery contents() method: introduced on PHP Chinese website
ID #sunP is the id of the input in the child iframe;

3. The child iframe calls the parent iframe Method

    window.parent.daoYo("asdadasds");
Copy after login

Window.parent directly calls the parent of the window object
daoYo("asdadasds"); The method name of the parent page, parameters can be passed;

4, The child iframe modifies the data in the parent iframe tag: such as modifying the input value in the parent iframe.
This goes without saying.

       window.parent.$("#button3").text("ssssssssssss");
Copy after login

Related recommendations:

iframe child, parent page intra-domain and cross-domain communication examples

The iframe height of the parent page automatically adapts to the iframe height of the child page_html/css_WEB-ITnose

jquery, js calls the iframe parent window and child window elements method arrangement_jquery

The above is the detailed content of A brief introduction to the mutual calling and value-passing methods between parent iframe and child iframe in jQuery. For more information, please follow other related articles on 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