Window. Opener usage and usage example

Source: Internet
Author: User

Window. Opener refers to the reference of the parent form of the sub-form through window. Open. The following describes the specific usage of the sub-form. If you are interested, refer

Window. opener is used to open the reference of the parent form of the child form through window. Open.

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

<Tr> <tdclass = "tdeditlabel"> Organization </TD> <tdclass = "tdeditcontent" colspan = "3" style = "width: 400px; text-align: left "> <input type =" hidden "name =" orgid "id =" orgidid "> <! -- Disabled: the modified content is not submitted --> <input type = "text" name = "orgname" Disabled = "disabled" id = "orgnameid"> <input type = "button" Name = "selectorgbutton" value = "" onclick = "openwin ('org. do? Select = true ', 'selectorg', 800,500, 1) "> </TD> </tr>

JS Code

/** Open a new window (via window. open () * F: link address * n: Window name * W: window width * H: window height * s: whether the window has a scroll bar; 1: whether a scroll bar exists; 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

<! -- List data bar --> <C: iftest = "$ {! Empty PM. datas} "> <C: foreachitems =" $ {PM. datas} "Var =" org "> <trbgcolor =" # eff3f7 "class =" tablebody1 "onmouseover =" this. bgcolor = '# dee7ff'; "onmouseout =" this. bgcolor = '# eff3f7'; "> <TD align =" center "valign =" center "> <input type =" radio "onclick =" selectorg ('$ {Org. id} ',' $ {Org. name} ') "> </TD> <tdalign =" center "valign =" center ">$ {Org. id} </TD> <tdalign = "center" valign = "center"> <ahref = "org. do? Parentid =$ {Org. id} & select = true ">$ {Org. name} </a> </TD> <tdalign = "center" valign = "center" >$ {Org. sn} </TD> <tdalign = "center" valign = "center" >$ {Org. parent. name }</TD> </tr> </C: foreach> </C: If>

JS Code

functionselectOrg(id,name){ if(window.opener){ window.opener.document.all.orgIdId.value= id; window.opener.document.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.

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.