How to use window object closed in JavaScript

In this article, I am going to explain about window object close property.
  • 2257

Closed property in JavaScript window object

In JavaScript window closed property, determine whether a window is closed or not.

Syntax of closed property


Browser support

The closed property is supported in all major browser.

Example of closed property

<!DOCTYPE html>



<script type="text/javascript">

    var MyWindow;

    function openWin() {

        MyWindow ="", "", "width=200,height=100");


    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!";







<input type="button" value="Open 'MyWindow'" onclick="openWin()" />

<input type="button" value="Close 'MyWindow'" onclick="closeWin()" />

<br /><br />

<input type="button" value="Has 'MyWindow' been closed?" onclick="checkWin()" />

<br /><br />

<div id="msg"></div>



closed propety.jpg

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here


More Articles

© 2020 DotNetHeaven. All rights reserved.