Search code examples
javascriptwindow

JS Open new window and close new window after N seconds


I want to open a new window using javascript(window.open("some_url")) and after some time i want to close that window. Is this possible using javascript?


Solution

  • Open the window, then use setTimeout to close after some interval.

    var newWindow = window.open("some_url");
    setTimeout(() => newWindow.close(), 1000);