Home >Web Front-end >JS Tutorial >A brief introduction to the mutual calling and value-passing methods between parent iframe and child iframe in jQuery
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>;
1. The parent iframe calls the method of the child iframe
$("#sunPage")[0].contentWindow.sunMethod();
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();
2. Parent iframe modifies the data in the child iframe tag: such as modifying the input value in the child iframe.
$('#sunPage').contents().find("#sunP").text("dsssssdd");
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");
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");
Related recommendations:
iframe child, parent page intra-domain and cross-domain communication examples
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!