So I make a new window using the open method and later call a setTimeout method to close it after 5 seconds but for some reason it doesnt close. I have tried to replicate this bug in another file like this: let win = window.open(”); setTimeout(function() {win.close()}, 5000); and it works just as intended( closes after 5 seconds). But in here it doesnt and when I’ve put some break points it just skips it and the program ends.
//Global variables
const button = document.getElementById("btn");
//Input-Fields
const nameInput = document.getElementById("input-name");
const phoneNumber = document.getElementById("input-phoneNum");
const adress = document.getElementById("input-adress");
//Variable
let confWindow;
function processInput()
{
//if statement checks if all fields contain something
//or true, if not they are falsy
if(nameInput.value && phoneNumber.value && adress.value)
{
//New Window size and centering
let winWidth = 300;
let winHeight = 300;
let leftPosition = ((screen.width - winWidth)/2);
let topPosition = ((screen.height - winHeight)/2);
//String that contains onptions for the new Window
let options = "width =" + winWidth + ",height="
+ winHeight + ", left =" + leftPosition
+ ", top =" + topPosition;
//creates a new window
confWindow = window.open("confirm.htm", "Confirm Page", options);
confWindow.document.write("<p>Hi</p>");
setTimeout(function(){confWindow.close()}, 5000);
}
else{
window.alert("Please Enter Information in all fields");
}
}
//Event Listeners
if(button.addEventListener)
{
button.addEventListener("click", processInput, false);
}
else if(button.attachEvent)
{
button.attachEvent("onclick", processInput);
}