You are here: irt.org | FAQ | JavaScript | Frame | Q1632 [ previous next ]
Normally when you need to close a poup window when the opener changes you would simply use the body tags onUnload event handler. I'm not sure if this will work in all browsers when used in a frameset tag. Instead you might want to test from the popup window that the opener window is still the same, perhaps by checking for a variable in the opener window. The following checks that the variable windowReference still exists and still references the popup window:
First the frame that opens the popup window:
<html>
<head>
<script language="JavaScript"><!--
var windowReference = window.open('popup.htm','windowName','width=100,height=100');
//--></script>
</head>
<frameset rows="50%,*" onUnload="if (!windowReference.closed) windowReference.close()">
<frame src="about:blank">
<frame src="about:blank">
</frameset>
</html>And the popup.htm:
<html>
<head>
<script language="JavaScript"><!--
function pollOpener() {
if (opener.windowReference && opener.windowReference == self)
setTimeout('pollOpener()',100);
else
slef.close();
}
setTimeout('pollOpener()',100);
//--></script>
</head>
<body>
...
</body>
</html>