The Window.closed
read-only property indicates whether the referenced window is closed or not.
The Window.closed
read-only property indicates whether the referenced window is closed or not.
A boolean value. Possible values:
true
: The window has been closed.false
: The window is open. The following example demonstrates how a popup window can change the URL of the window that opened it. Before attempting to change the URL, it checks that the current window has an opener using the window.opener
property and that the opener isn't closed:
js
// Check that an opener exists and is not closed if (window.opener && !window.opener.closed) { window.opener.location.href = "http://www.mozilla.org"; }
Note that popups can only access the window that opened them.
In this example the function refreshPopupWindow()
calls the reload()
method of the popup's location object to refresh its data. If the popup hasn't been opened yet or the user has closed it a new window is opened.
js
let popupWindow = null; function refreshPopupWindow() { if (popupWindow && !popupWindow.closed) { // popupWindow is open, refresh it popupWindow.location.reload(true); } else { // Open a new popup window popupWindow = window.open("popup.html", "dataWindow"); } }
Specification |
---|
HTML Standard # dom-window-closed-dev |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
closed |
1 | 12 | 1 | 4 | ≤12.1 | 1 | 4.4 | 18 | 4 | ≤12.1 | 1 | 1.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Window/closed