javascript – How to create a prompt in a new tab opened with window.open

Code:

button = document.getElementById('button');
function buttonPress(){
    input = document.getElementById('input');
    url = input.value;
    console.log(url);
     let a = window.open(url,"name");
     a.focus();
    setTimeout(console.log("wait until confirm"),4000);
    if(confirm('Start download?')){
        alert('Downloading');
    }
    else{
        alert('Why you no love me...');
        window.close;
    }
}
button.addEventListener("click",buttonPress)

The problem is that the confirm opens in the previous tab, not in the new one. I’ve tried with location.replace or href but it still doesn’t work. Any ideas how I could get there?