[Javascript] Active windows - child reloads parent

Paul Novitski javascriptlist at dandemutande.org
Sun Dec 14 01:09:45 CST 2003


Tim & Peter,

Another way to do this is with onUnLoad(), reload(), and opener.

The onUnLoad() event executes if the current window is closed, reloaded, or 
loaded with another page.  The reload() method refreshes the referenced 
window.  The opener property refers to the parent of the current (child) 
window.

In the child window you can execute:
         window.opener.document.location.reload();
or more simply:
         window.opener.location.reload();

Here's a demo involving two html files.  Open the parent window, then click 
on the link to open the child.  You can refresh the date/time display in 
the parent from the child window by clicking on the first link, and when 
you close the child window (either by clicking on the second link or by 
using the window's own Close control) the parent's date display is likewise 
refreshed.

Paul
____________________________________

<!-- onUnLoadParent.html -->

<html>
<head>
<title>Parent window</title>
</head>
<body>

onUnLoadParent.html<br><br>

<a target="_blank" href="onUnLoadChild.html">Create child</a>.<p>

<script language="Javascript">
var strDate = new Date;
document.write ("Parent was last loaded " + strDate.toLocaleString());
</script>

</body>
</html>
____________________________________

<!-- onUnLoadChild.html -->

<html>
<head>
<title>Child window</title>
<script language="Javascript">
function ReloadParent(){
window.opener.document.location.reload();
}
</script>
</head>
<body onUnLoad='ReloadParent();'>

onUnLoadChild.html<p>

<a href="#" onClick="ReloadParent();">Reload parent</a>.<p>

<a href="#" onClick="window.close(); ReloadParent();">Close child & reload 
parent</a>.

</body>
</html>
____________________________________






More information about the Javascript mailing list