HTML | DOM Window closed Property
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 >
< button onclick="openWindow()">
Open Window
</ button >
< button onclick="closeWindow()">
Close Window
</ button >
</ body >
</ html >
|
Output:
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
Share your thoughts in the comments
Please Login to comment...