HTML | DOM Window closed Property

The Window closed property in HTML DOM is used to return a value that indicates whether the referred window is closed or not.

Syntax:

window.close()

Return Value: A Boolean value, true if window is closed otherwise false.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1,
        h2 {
            color: green;
        }
          
        body {
            text-align: center;
        }
    </style>
    <script>
        var gfgWindow;
        
        // function to open a window.
        function openWindow() {
            gfgWindow = window.open("",
             "Window", "width=400, height=200");
        }
        
        // function to close a window.
        function closeWindow() {
            if (gfgWindow) {
                gfgWindow.close();
            }
    alert("Window Closed");
        }
    </script>
</head>
  
<body>
    <h1>GeeksForGeeks</h1>
    <h2>HTML | DOM Window closed Property</h2>
  
    <!--Click on Open Window to open a Window-->
    <button onclick="openWindow()">
        Open Window
    </button>
  
    <!--Click on Close Window to close a Window-->
    <button onclick="closeWindow()">
        Close Window
    </button>
  
</body>
  
</html>

chevron_right


Output:

  • Initial:
  • Window open:
  • Window close:

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.