Edit This Code:
<!DOCTYPE html>
<html>
<head>

<script>
var myWindow;
function openWin() {
    myWindow = window.open("", "", "width=400 ,height=200");
}

function closeWin() {
    if (myWindow) {
        myWindow.close();
    }
}

function checkWin() {
    msg = ""
    if (!myWindow) {
        msg = "was never opened";
    } else {
        if (myWindow.closed) {
            msg = "is closed";
        } else {
            msg = "is open";
        }
    
    }        
    document.getElementById("msg").innerHTML =
    "myWindow " + msg;
}
</script>

</head>
<body>

<button onclick="openWin()">Open myWindow</button>
<button onclick="closeWin()">Close myWindow</button>
<button onclick="checkWin()">Is myWindow open?</button>

<br><br>
<div id="msg"></div>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy