T
T
tera1oo42020-04-22 00:32:39
JavaScript
tera1oo4, 2020-04-22 00:32:39

How to make the correct closing of the tab through window.close?

There is a code that should automatically open the site every time interval, and close it in the same way.
When I run it in the console in the browser, the pages open, but the tabs are not closed, but the one on which the code was run. How can I close the tabs opened with the same code?

function openWindow() {
  openedWindow = window.open("https://www.youtube.com/");}


function closeOpenedWindow()  {
  openedWindow.close();}


    
  setInterval(openWindow,3000);
  setInterval(closeOpenedWindow,10000);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2020-04-22
@xmoonlight

Either make the window id a global variable, or pass it inside the close function.
Delay - put inside the opening function (immediately after loading).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question