Test: window.close()

Browsers that have been tested

  • Chrome 89 passed
  • Firefox 86 passed
  • Edge 89 passed
  • Safari 14 failed

In Safari, it seems to be available only when it is opened with Script, in the original sense.

If I can find out how to determine the script closable in Safari, I will add it.

window.close() is only available in limited situations. This page is intended to test it.

Let's see if the close button works.

A browsing context is script-closable if it is an auxiliary browsing context that was created by a script (as opposed to by an action of the user), or if it is a top-level browsing context whose session history contains only one Document.

HTML Living standard: https://html.spec.whatwg.org/multipage/window-object.html#dom-window-close

In actuality, window.close() will available when one of the following rules is positive.

  • If window.opener is not null
  • If window === window.top is true and window.history.length is 1
Related status
script-closableProbably ...
top level browsing context

Links for test and a close button

The following links all lead to the same page as this one.

Note: The link "Same Tab" is given unique query by JavaScript. Because, does not increase the history if the URL is perfectly the same as current.

The iframe element for check a browsing context

If the current browsing context is the top level (window.top === window), a page same as this page will be inserted as an iframe element.