Browser API | Close window programmatically

42 Views Asked by At

Is there an API that can be used to close a tab programmatically? I know there is the method window.close(), but it can be used only for the windows that were opened by a script using the window.open() method.

What I am trying to do is create a menu button for the users that once clicked will close the current tab or all other tabs if the current tab has been duplicated.

1

There are 1 best solutions below

6
Daniel Hakobyan On

Is there an API that can be used to close a tab programmatically?

NO it is impossible,

For security reasons, a window can only be closed in JavaScript if it was opened by JavaScript.

You must edit your code and use windows.open(), to use windows.close() method.