irt.org Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt

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

You are here: irt.org | FAQ | JavaScript | Window | Q1209 [ previous next ]

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()">

...

©2013 Martin Webb

ArticlesFAQsGamesFeedback

FOLDOCRFCsInstant JavaScriptSoftwareBooksJavaScript Programmer's ReferenceAboutTop