You are here: irt.org | FAQ | JavaScript | Window | Q1137 [ previous next ]
You can check to see if the window has been opened then subsequently closed with:
<script language="JavaScript"><!-- var windowHandle = null; function openWindow() { windowHandle = window.open('http://www.irt.org/','windowName','height=200,width=200'); if (!windowHandle.closed) window.closed = false; } function closeWindow() { if (windowHandle != null) { if (windowHandle.closed) { // already opened and closed } else { windowHandle.closed = true; windowHandle.close(); } } else // not yet opened } //--></script>
Micke Kazarnowicz writes:
The original didn't work (generated error messages in Internet Explorer 5.0) and worked only once in Netscape 4.7. This one [following] doesn't generate any error messages, and can open and close the window an infinite number of times:
<script language="JavaScript"><!-- var windowHandle = null; var windowHandle_closed = false; function openWindow() { windowHandle = window.open('http://www.irt.org/','windowName','height=200,width=200'); if (windowHandle_closed) { windowHandle_closed = false; } } function closeWindow() { if (windowHandle != null) { if (!windowHandle_closed) { windowHandle_closed = true; windowHandle.close(); } } } //--></script>