JavaScript: Refreshes the parent window when a pop-up window is closed

Source: Internet
Author: User

JavaScript: Refreshes the parent window when a pop-up window is closed

2010-08-13 09:25:29| Category: Code samples | Report | Font size Subscription

Description : Refreshing the parent window when a pop-up window is closed can also be said to automatically refresh the information in the parent window when the child window is closed, that is, the user opens a new window (child window) through the Window object's open () method, when the user makes database operations in that child window (such as data addition, Modify and delete, etc.), when the child window is closed, the system automatically refreshes the parent window to update the information in real time;

ideas and Techniques :

The main application of the window.open () statement opens a new window and applies the opener property in a new window, which returns a reference that specifies the Window object that opens the window.

& Syntax:

Window.opener

Window.opener. Methods

Window.opener. Properties

Function: Returns a Window object. The opener property is associated with the parent window that opens the window, and when you access the opener property in the child window, the parent window is returned, which allows you to use the methods and properties in the parent window object.

Attention:

If the window is not opened by another window, this property returns Null in Netscape and "undefined" (undefined) in IE. Undefined to a certain extent equal to null. It is necessary to note that undefined is not a JavaScript constant, and if the reader attempts to use undefined, it really returns "undefined".

The reload () method is equivalent to clicking the Refresh (IE) or reload (NETSCAP) button on the browser

Code 1 (Opens a new window):

<a href= "#" onclick= "Javascript:window.open (' meeting_add.jsp ', ' ', ' width=560,height=397 ')" > Hyperlinks </a>

Code 2 (Close the pop-up window and refresh the main page):

<script language= "JavaScript" >

Alert ("The meeting record was saved successfully! ");

Window.opener.location.reload (); Refresh a page in the parent window

Window.close ();//close the current window

</script>

Code 3 (Close the pop-up and refresh the main page, focus on the recommended method):

<script language= "JavaScript" >

function Save () {
document.getElementById ("Pointsform"). Submit ();

Alert (' Save Success ');

Window.opener.document.getElementById ("cmd"). value= "Query";

Window.opener.document.getElementById ("Khxzform"). Submit ();

Window.close ();
}

</script>

JavaScript: Refreshes the parent window when a pop-up window is closed

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.