Click to See Complete Forum and Search --> : Closing child window with parent


IxxI
02-12-2003, 09:23 AM
Is there anyway to make a child window close when the parent window that spawned it closes? For example an authentication applet which opens as you open a page (which I have already) but once you close that page (ie close the explorer window NOT browse to a different page) the applet closes.
IxxI

gil davis
02-12-2003, 09:44 AM
All you have is onunload and onbeforeunload. But you cannot tell the difference between navigating and closing the browser. Also, if the user navigates, you would lose the parent/child relationship anyway.

This is probably as close as you can get:

<head>
<script>
var it = null;
function openit() {
it = window.open("","it","width=200,height=200");
}
function closeit() {
if (it != null)
{if (!it.closed) it.close();}
}
</script>
</head>
<body onunload="closeit()">
<a href="#" onclick="openit();return false">open</a>
</body>

IxxI
02-12-2003, 10:53 AM
Thanks for the reply. The thing is its for an intranet, and people need to have this window open to be on the internet - they have to type in their username and password and while the applet is open they can go on. This used to work (I had nothing to do with the coding) but we've recently upgraded and it now doesn't, so I've been landed with the job of sorting it (apparently it's too hard to close a window yourself). Can anyone think of a way it could have been linked to the browser window??
IxxI