Ask coding questions

← Back to all posts
Window.Close not working?
MikeJMS8910 (231)

So I have a code that opens up a tab and then once the tab has loaded it will close the tab. Here is the code -

let x = true;

while(x == true) {
let y = window.open("https://google.com")
y.onload = y.close()
}

What it does do is just open the tab up very fast but never close it. So why is it not working and how can I fix this?

Comments
hotnewtop
Coder100 (18238)

first off,
never ever use while true loops that don't terminate, because it will crash your browser and be slow!!

Second, the code works?

MikeJMS8910 (231)

@Coder100 if I put it in the inspector it doesn't work for me