The Window.close() method closes the current window, or the window on which it was called.
This method can only be called on windows that were opened by a script using the Window.open() method, or on top-level windows that have a single history entry. If the window doesn't match these requirements, an error similar to this one appears in the console: Scripts may not close windows that were not opened by script.
Note also that close() has no effect when called on Window objects returned by HTMLIFrameElement.contentWindow.