<!DOCTYPE html>
<html>
<body>
<h1>The Window Object</h1>
<h2>The closed Property</h2>
<p><button onclick="openWin()">Open "myWindow"</button></p>
<p><button onclick="closeWin()">Close "myWindow"</button></p>
<p><button onclick="checkWin()">Is "myWindow" closed?</button></p>
<div id="demo"></div>
<script>
let myWindow;
function openWin() {
myWindow = window.open("", "myWindow", "width=400,height=200");
}
function closeWin() {
if (myWindow) {
myWindow.close();
}
}
function checkWin() {
let text = "";
if (!myWindow) {
text = "It has never been opened!";
} else {
if (myWindow.closed) {
text = "It is closed.";
} else {
text = "It is open.";
}
}
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
</html>