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

Q1209 Is it possible to close the main window and all the popup windows at the same time?

irt.org | Knowledge Base | JavaScript | Window | Q1209 [ previous next ]

Q1209 Is it possible to close the main window and all the popup windows at the same time?

The onUnload event of the main page is triggered when the user leaves the page or closes the window. You will need to test if the user just follows a link, but the code to close the windows first require that you store all the references to the winods you open in an array:

<html>
<head>
<script language="JavaScript"><!--
var WinIds = new Array();
CurrentWin = 0;
WinId[CurrentWin++] = window.open('popup1.htm');
...
WinId[CurrentWin++] = window.open('popup2.htm');

function closeAll() {
    for (i=0;i<WinId.length;i++) {
        if (WinId[i] && !WinId[i].closed) WinId[i].close();
    }
}
//--></script>
</head>

<body onUnload="closeAll()">

...

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.