Try this:
var win = window.open(url, name);
win.onunload = afterChildClose; // afterChildClose() is the function.
win.close(); // afterChildClose() should fire now.
All this code would be located and executed in the parent window's javascript (including afterChildClose()). You are creating the window and assigning the function to the unload event.
Oh, one thing I just thought of. If the child window refreshes or navigates to another url, the onunload event will fire as well. If you only want the event to fire when the window is closed, you should include a check in afterChildClose() on win.closed.
EDIT: Here is the code to two sample pages I put together to try this out.
Parent window:
<html>
<body>
<script type="text/javascript">
var win = window.open("secondwindow.html", "woo");
win.onunload =onun;
function onun() {
if(win.location != "about:blank") // This is so that the function
// doesn't do anything when the
// window is first opened.
{
alert("closed");
}
}
</script>
</body>
</html>
child window ("secondwindow.html"):
<html>
<body>
<script type="text/javascript">
setTimeout('window.close();', 5000);
</script>
</body>
</html>
When I try opening the first document in firefox, it opens the window, the window waits 5 seconds and quits, and the first document shows the alert(), so it is working even when the sub window closes itself.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…