Conversion between window. parent and window. opener

Source: Internet
Author: User

1: window. parent is the parent page object called by the iframe page

Example:
A.html

 

Program code <Head> <title> parent page </title> <Body>
<Form name = "form1" id = "form1">

<Input type = "text" name = "username" id = "username"/>

</Form>
<Iframe src = "B .html" width = 100%> </iframe>
</Body>
</Html>

To assign a value to the username text box in a.htm in B .htm, for example, many upload functions. The upload function page is in Ifrmae. After the upload is successful, the uploaded path is placed in the text box of the parent page.

We should write in B .html

Program code <script type = "text/javascript">
Var _ parentWin = window. parent;
_ ParentWin. form1.username. value = "xxxx ";
</Script>

2: window. opener is a child page opened by window. open. It calls the parent page object.

A.html

Program code <script type = "text/javascript">
Function openSubWin ()
{
Var _width = 300;
Var _ height = 200;
Var _ left = (screen. width-_ width)/2;
Var _ top = (screen. height-_ height)/2;
Window. open ("B .html", null,
"Height =" + _ height + ", width =" + _ width + ", status = no, toolbar = no, menubar = no, location = no, resizable = yes, left = "+ _ left +", top = "+ _ top );
}
</Script>
<Input type = "text" name = "username" id = "username"/>
<Input type = "button" value = "pop-up subpage" onClick = "openSubWin ();">

B .html

Program code <script type = "text/javascript">
Function UpdateParent ()
{
Var _ parentWin = window. opener;
_ ParentWin. form1.username. value = "xxxx ";
}
</Script>
<Input type = "button" name = "button" id = "button" value = "update the UserName content on the home page" onClick = "UpdateParent ();">

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.