How to close an open window after the user has searched something in the open window(using JavaScript)?

Viewed 36

I'm currently building a video game on the web, it's a millionaire. I came up with the idea that as one of the help, I would enable users to use google for 20 seconds. I managed to open a window with a search engine, but after 20 seconds I want to close it, this is not possible if the user has searched something.

newWindow=window.open('https://google.com','mywindow', 'width=375px, height=400px, top=200px')
setTimeout(() =>{
    newWindow.close()
},22000)

I also watched this tutorial: https://www.youtube.com/watch?v=2Qu8mwQizbM

1 Answers

Closing another window from JS should not be possible, as your code only has control of your tab. One way you could do what you're trying to do is to create an <iframe> then remove it after 20 seconds with setTimeout().

Related