Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Window: closed property

BaselineWidely available

TheWindow.closed read-only property indicates whetherthe referenced window is closed or not.

Value

A boolean value. Possible values:

  • true: The window has been closed.
  • false: The window is open.

Examples

Change the URL of a window from a popup

The following example demonstrates how a popup window can change the URL of the windowthat opened it. Before attempting to change the URL, it checks that the current windowhas an opener using thewindow.opener property and that the opener isn'tclosed:

js
// Check that an opener exists and is not closedif (window.opener && !window.opener.closed) {  window.opener.location.href = "https://www.mozilla.org";}

Note that popups can only access the window that opened them.

Refreshing a previously opened popup

In this example the functionrefreshPopupWindow() calls thereload() method of the popup's location object to refresh its data. If thepopup 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");  }}

Specifications

Specification
HTML
# dom-window-closed-dev

Browser compatibility

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp