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
window.close() will available when one of the following rules is positive.
window === window.topis
|top level browsing context|
Links for test and a close button
The following links all lead to the same page as this one.
- Open in same tab
- Open in new tab [target=_blank]
- Open in new tab [target=_blank][rel=opener]
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.