Interaction between a javascript subwindow and a parent window

Source: Internet
Author: User
This article is reproduced in: http://blog.csdn.net/fenglibing/archive/2007/09/11/1781243.aspx

1,Pass a value to the parent window from the Child WindowIf the parent page has a controlled ID choosedprovider, you can pass the value to the parent page: opener.doc ument. getelementbyid ("choosedprovider"]). value = "Tom ";2,Pass a value from the parent window to the Child Window. If the child window contains an IDTIn this case, you can use the following values:<SCRIPT> var newwindow; function OpenWindow (URL) {newwindow = too many open(“new.htm "," "," width = 400, Height = 300 ");} function changechild({{new}{doc ument. getelementbyid ("T "). value = "I changed" ;}</SCRIPT> first grabs the handle and then operates through the handle. In fact, compare the values transmitted from the Child window above to the parent window, the operation object is changed.3,Close the Child Window and refresh the parent interface. There are two methods:A) Close the parent window when the child window is closed: opener. location. reload (); window. close (); B) Check the parent window. If the child window is closed, it is automatically refreshed after a specified period of time: <SCRIPT> var newwindow; var timer; function OpenWindow (URL) {newwindow = Window. open (URL, "", "width = 400, Height = 300, resizable = yes"); timer = setinterval ("updateafterclose ()", 1000);} function updateafterclose () {// The parent window checks whether the child window is closed and refresh itself, instead of refreshing the parent window if (newwindow. closed = true) {clearinterval (timer); self. location. reload (); // refresh return in the main window; }}</SCRIPT>4,Close the child window when the parent window is closed. This is how to check the onUnload of the parent window.Event:<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 ()">5,Close the parent window in the Child window. This function may be less useful:<SCRIPT> function closeparent () {opener. Close () ;}</SCRIPT> <input type = button value = "close parent window" onclick = closeparent ()>

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.