Window. opener usage and usage example _ javascript skills

Source: Internet
Author: User
Window. opener, via window. open the reference of the parent form of the child form. The following describes how to use it in detail. If you are interested, refer to window. opener, via window. open refers to the parent form of the child form.

For example, in the parent form parentForm, window. open ("subForm.html") means window. opener represents parentForm in subForm.html. Since the reference of the parent form can be obtained in the child form, you can set the field value of the parent form in the child form or call the js method.
Instance: when adding personnel information, the organization information is entered in the subform.
Father form, used to add personnel information.

After the child form is input, the organization information (id and name) is automatically filled in the orgId and orgName fields of the parent form.

Html code

The Code is as follows:



Institution




Onclick = "openWin ('org. do? Select = true ', 'selectorg', 800,500, 1) ">



JS Code

The Code is as follows:


/*
* Open a new window (via window. open ())
* F: link address
* N: Window name
* W: The window width.
* H: window height
* S: whether the window has a scroll bar; 1: A scroll bar; 0: No scroll bar.
*/
FunctionopenWin (f, n, w, h, s ){
Sb = s = "1 "? "1": "0 ";
L = (screen. width-w)/2;
T = (screen. height-h)/2;
SFeatures = "left =" + l + ", top =" + t + ", height =" + h + ", width =" + w
+ ", Center = 1, scrollbars =" + sb + ", status = 0, directories = 0, channelmode = 0 ";
Openwin = window. open (f, n, sFeatures );
If (! Openwin. opener)
Openwin. opener = self;
Openwin. focus ();
Returnopenwin;
}


Sub-form for selecting organization information.

After selecting (Click radio), the organization information (id and name) will be filled in the orgId and orgName fields of the parent form

Html code

The Code is as follows:









$ {Org. id}
$ {Org. name}
$ {Org. sn}
$ {Org. parent. name}




JS Code

The Code is as follows:


FunctionselectOrg (id, name ){
If (window. opener ){
Zookeeper opener.doc ument. all. orgIdId. value = id;
Zookeeper opener.doc ument. all. orgNameId. value = name;
Window. close ();
}
}


Result After selecting organization information

The organization information (id and name) is entered, but the id is in the hidden domain and cannot be seen.
Summary
When it comes to references to the parent form, besides window. opener, It is window. parent. Window. opener is used to open sub-forms through window. open, while window. parent is used to open sub-forms through iframe.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.