Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1632 How do I close a window opened by a frame when a new page loads into the creating frame?

irt.org | Knowledge Base | JavaScript | Frame | Q1632 [ previous next ]

Q1632 How do I close a window opened by a frame when a new page loads into the creating frame?

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.