[Javascript] Active windows - child reloads parent

Peter Brunone peter at brunone.com
Mon Dec 15 14:53:30 CST 2003


Paul,

	That's a viable solution, but in my experience (and that of many
others), the onUnload event handler can be unreliable about firing every
time a window closes.

Just my additional 2 cents...

Peter

-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu] On Behalf Of Paul Novitski

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