skip to Main Content

What i see in docs that if you open the tab manually using window.open then you have option to close it.

 openNewWindow() {
    const newWindow = window.open('https://www.google.com/', 'hello');
    setTimeout(() => {
      newWindow?.close();
    }, 100);
  }

Playground Link: Playground

2

Answers


  1. It depends on the internet speed. If opening a new window takes more than 100ms. The newWindow object is not yet initialized and newWindow?.close() will not be executed.

    Login or Signup to reply.
  2. Your code seems to work with other URLs.

    Try with example.org or developer.mozilla.org.

    Maybe www.google.com has a feature that prevents the window from being closed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search