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 notnull
- If
window === window.top
istrue
andwindow.history.length
is 1
script-closable | Probably ... |
---|---|
top level browsing context |
|
window.opener |
|
window.history.length |
|
document.referrer |
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.
- Open in same tab
- Open in new tab [target=_blank]
- Open in new tab [target=_blank][rel=opener]
- Open in new tab by JavaScript(window.open)
- Open in new tab by JavaScript(window.open - noopener)
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.