Detailed description of JS subwindow operation parent window instance

Source: Internet
Author: User

We only need to use newclientclientdoc ument. getElementById and opener. location. reload to operate on each other. You can refer to them.

1. Pass a value from the Child Window to the parent window

If the parent page has a control id of choosedProvider, you can pass the value to the parent page:

The Code is as follows: Copy code
Opener.doc ument. getElementById ("choosedProvider"]). value = "Tom ";

2. Pass a value from the parent window to the Child Window. For example, if the child window contains a control whose id is T, you can use the following values:

The Code is as follows: Copy code

<Script>
Var newWindow;
Function openWindow (url ){
NewWindow = zookeeper open(“new.htm "," "," width = 400, height = 300 ");
}
Function changeChild (){
Newmediaworkflow Doc ument. getElementById ("T"). value = "I changed ";
}
</Script>

When a child window is closed again, the parent window is automatically refreshed.

Close the parent window when the child window is closed:

Opener. location. reload ();
Window. close ();


The actual effect is as follows: Open 1.htm, click link to new window 2.htm, click link in 2.htm, and close the new window.
1.htm window redirection.

The 1.htm code is as follows:

The Code is as follows: Copy code

<Html>
<Body>
<A href00002.htm onclick00000000000000000000open('2.htm') "> new </a>
</Body>
</Html>

2.htm code:

The Code is as follows: Copy code

<Html>
<Body>
<A href = # onclick = "opener. location. href = 'HTTP: // baidu.com '; window. close ()"> nbn </a>
</Body>
</Html>

We only used the Child Window to operate the upper-pole window. Of course, we can also operate the child parent window together.

Close the child window when the parent window is closed. This is to use the method to detect the onunload Event of the parent window:

The Code is as follows: Copy code
<Script>
Var newWindow;
Function openWindow (url ){
NewWindow = window. open (url, "", "width = 400, height = 300, resizable = yes ");
}
Function closeChild ()
{
NewWindow. close ();
}
</Script>
Add the onunload Event to the body:
<Body onunload = "closeChild ()">

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.