html代码
Home > Web Front-end > JS Tutorial > body text

Introduction to window.opener usage and usage examples_javascript skills

WBOY
Release: 2016-05-16 17:25:11
Original
1373 people have browsed it

window.opener is a reference to the parent form that opens the child form through window.open.

For example, in the parent form parentForm, through window.open("subForm.html"), then window.opener in subform.html represents parentForm. Since you can get a reference to the parent form in the subform, you can set the field values ​​of the parent form or call js methods in the subform.
Example: When adding personnel information, the organization information is entered through the subform.
The parent form is used to add personnel information.

After the subform completes the input, the organization information (id, name) is automatically filled in the orgId and orgName fields of the parent form
Introduction to window.opener usage and usage examples_javascript skills
html code

Copy code The code is as follows:


Institution



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



JS code
Copy code The code is as follows:

/*
*Open a new window (via window.open())
* f: link address
* n: window Name
* w: Width of window
* h: Height of window
* s: Whether the window has scroll bars, 1: There are scroll bars; 0: No scroll bars
*/
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;
}

Subform for selecting institution information.

When selected (by clicking radio), the organization information (id, name) will be filled in the orgId and orgName fields of the parent form
Introduction to window.opener usage and usage examples_javascript skills
html code
Copy code The code is as follows:


< c:iftest="${!empty pm.datas}">





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




JS code
Copy code The code is as follows:

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 institution information
Introduction to window.opener usage and usage examples_javascript skills
The input of the organization information (id, name) has been completed, but the id is in the hidden field and cannot be seen.
Summary
Speaking of references to the parent form, in addition to window.opener, it is window.parent. window.opener is used to open a subform through window.open, and window.parent is used to open a subform through iframe.
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!