Window closed Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window closed


The closed property returns a Boolean value indicating whether a window has been closed or not.

Return Value

A Boolean, true if the window has been closed, or false if the window is open

The following code shows how to check whether a window called "myWindow" has been closed or not:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

var myWindow;/*from  w ww.  j ava  2  s  . c  o m*/

function openWin() {
    myWindow ="", "myWindow", "width=400, height=200");

function closeWin() {
    if (myWindow) {

function checkWin() {
    if (!myWindow) {
        document.getElementById("msg").innerHTML = "'myWindow' has never been opened!";
    } else {
        if (myWindow.closed) {
            document.getElementById("msg").innerHTML = "'myWindow' has been closed!";
        } else {
            document.getElementById("msg").innerHTML = "'myWindow' has not been closed!";


<button onclick="openWin()">Open "myWindow"</button>
<button onclick="closeWin()">Close "myWindow"</button>
<button onclick="checkWin()">Has "myWindow" been closed?</button>
<div id="msg"></div>


Related Tutorials