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