Home  >  Article  >  Web Front-end  >  JavaScript calling method between parent and child forms_javascript skills

JavaScript calling method between parent and child forms_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:06:501123browse

The example in this article describes the calling method between JavaScript parent and child forms. Share it with everyone for your reference. The details are as follows:

If you want to open a new window, use the window.open() method.

If you want to close your own window, use the window.close() method.

1. Parent form

In order to facilitate the parent window to operate the child window, you can define a variable for the window.open() method, for example:

var opW = window.open("tests.html","popup","width=300,height=300");

In this way, to close the sub-window, you can directly use: opW.close() method.

If the parent form wants to operate child window elements, the code is as follows:

Copy code The code is as follows:
opW.document.getElementById("fartherWindowTxt").innerHTML = "Operation Child Window" ;

2. Subform

The child window can use window.opener to reference the parent window, the code is as follows:

Copy code The code is as follows:
window.opener.document.getElementById("fartherWindowTxt").innerHTML= "Child window Operate the parent window! ";

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
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