This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The Window.close() method closes the current window, or the window on which it was called.
Windows are script-closable if they were created by web content. This generally includes:
Window.open()
<a target="_blank">) or forms (<form target="_blank">), without user modifier actionsWindows opened by browser UI actions — such as right-click → Open in new tab, Ctrl+Click, Shift+Click, or middle-click — are often not script-closable. They may only be closed if they have not been navigated (history length remains 1). Calling close() otherwise typically shows a console warning: 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.
close()
None.
None (undefined).
window.open()
This example shows a method which opens a window and a second one which closes the window; this demonstrates how to use Window.close() to close a window opened by calling window.open().
// Global variable to store a reference to the opened window
let openedWindow;
function openWindow() {
openedWindow = window.open("more-info.htm");
}
function closeOpenedWindow() {
openedWindow.close();
}
| Specification |
|---|
| HTML> # dom-window-close-dev> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
close |
1 | 12Before Edge 79, scripts can close windows that weren't opened by the same script. |
1Before Firefox 46, scripts can close windows that weren't opened by the same script. |
3 | 1 | 18 | 4Before Firefox for Android 46, scripts can close windows that weren't opened by the same script. |
10.1 | 1 | 1.0 | 4.4 | 1 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Window/close