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:
<!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
filter_none
Output:
- Initial:

- Window open:

- Window close:
Supported Browsers:
- Google Chrome
- Internet Explorer
- Firefox
- Safari
- Opera
Recommended Posts:
- HTML | Window top( ) Property
- HTML | Window self( ) Property
- HTML | Window name Property
- HTML | Window pageXOffset Property
- HTML | Window innerHeight Property
- HTML | Window innerWidth Property
- HTML | Window length Property
- HTML | Window pageYOffset Property
- HTML | Window outerWidth Property
- HTML | Window sessionStorage( ) Property
- HTML | Window screenX Property
- HTML | Window screenY Property
- HTML | DOM Window parent Property
- HTML | Window outerHeight Property
- HTML | Window screenTop Property
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.



