Although there are no error messages, I am encountering an issue where the function windowClose()
does not execute when I click on the 'close window' button. Why could this be happening?
Take a look at my code below:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="button" value="open window" onclick="windowOpen()">
<input type="button" value="close window" onclick="windowClose()">
<script src="window.js"></script>
</body>
</html>
JS
let myWindow;
function windowOpen(){
myWindow = window.open("https://google.com", "_blank");
}
function windowClose(){
myWindow.close();
}
I had anticipated that clicking on the 'close window' button would result in the new window closing as expected.