Skip to content
Related Articles

Related Articles

HTML | DOM Window closed Property

View Discussion
Improve Article
Save Article
  • Last Updated : 05 Aug, 2022

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: 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML | DOM Window closed Property
    </title>
    <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>

Output:

  • Initial: 

  • Window open: 

  • Window close:

 

Supported Browsers: The browser supported by DOM Window closed Property are listed below:

  • Google Chrome 1
  • Edge 12
  • Internet Explorer 4
  • Firefox 1
  • Opera 12.1
  • Safari 1

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!