Skip to content
Related Articles

Related Articles

Improve Article
HTML | DOM Window closed Property
  • Last Updated : 26 Jul, 2019

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:




<!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
  • Internet Explorer
  • Firefox
  • Opera
  • Safari



My Personal Notes arrow_drop_up
Recommended Articles
Page :