Window.closed read-only property indicates whether the referenced window is closed or not.

句法

const isClosed = windowRef.closed;
					

A 布尔 . Possible values:

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

范例

Change the URL of a window from a popup

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:

// 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.

Refreshing a previously opened popup

In this example the function refreshPopupWindow() 调用 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.

const 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');
  }
}
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'window.closed' in that specification.
实时标准

元数据

  • 最后修改:
  1. Window
  2. 特性
    1. applicationCache
    2. caches
    3. closed
    4. console
    5. controllers
    6. crossOriginIsolated
    7. crypto
    8. customElements
    9. defaultStatus
    10. devicePixelRatio
    11. dialogArguments
    12. 目录
    13. document
    14. event
    15. frameElement
    16. frames
    17. fullScreen
    18. history
    19. indexedDB
    20. innerHeight
    21. innerWidth
    22. isSecureContext
    23. isSecureContext
    24. length
    25. localStorage
    26. location
    27. locationbar
    28. menubar
    29. mozAnimationStartTime
    30. mozInnerScreenX
    31. mozInnerScreenY
    32. mozPaintCount
    33. 名称
    34. navigator
    35. onabort
    36. onafterprint
    37. onanimationcancel
    38. onanimationend
    39. onanimationiteration
    40. onappinstalled
    41. onauxclick
    42. onbeforeinstallprompt
    43. onbeforeprint
    44. onbeforeunload
    45. onblur
    46. oncancel
    47. oncanplay
    48. oncanplaythrough
    49. onchange
    50. onclick
    51. onclose
    52. oncontextmenu
    53. oncuechange
    54. ondblclick
    55. ondevicelight
    56. ondevicemotion
    57. ondeviceorientation
    58. ondeviceorientationabsolute
    59. ondeviceproximity
    60. ondragdrop
    61. ondurationchange
    62. onended
    63. onerror
    64. onfocus
    65. onformdata
    66. ongamepadconnected
    67. ongamepaddisconnected
    68. ongotpointercapture
    69. onhashchange
    70. oninput
    71. oninvalid
    72. onkeydown
    73. onkeypress
    74. onkeyup
    75. onlanguagechange
    76. onload
    77. onloadeddata
    78. onloadedmetadata
    79. onloadend
    80. onloadstart
    81. onlostpointercapture
    82. onmessage
    83. onmessageerror
    84. onmousedown
    85. onmouseenter
    86. onmouseleave
    87. onmousemove
    88. onmouseout
    89. onmouseover
    90. onmouseup
    91. onmozbeforepaint
    92. onpaint
    93. onpause
    94. onplay
    95. onpointercancel
    96. onpointerdown
    97. onpointerenter
    98. onpointerleave
    99. onpointermove
    100. onpointerout
    101. onpointerover
    102. onpointerup
    103. onpopstate
    104. onrejectionhandled
    105. onreset
    106. onresize
    107. onscroll
    108. onselect
    109. onselectionchange
    110. onselectstart
    111. onstorage
    112. onsubmit
    113. ontouchcancel
    114. ontouchstart
    115. ontransitioncancel
    116. ontransitionend
    117. onunhandledrejection
    118. onunload
    119. onuserproximity
    120. onvrdisplayactivate
    121. onvrdisplayblur
    122. onvrdisplayconnect
    123. onvrdisplaydeactivate
    124. onvrdisplaydisconnect
    125. onvrdisplayfocus
    126. onvrdisplaypointerrestricted
    127. onvrdisplaypointerunrestricted
    128. onvrdisplaypresentchange
    129. onwheel
    130. opener
    131. origin
    132. outerHeight
    133. outerWidth
    134. pageXOffset
    135. pageYOffset
    136. parent
    137. 性能
    138. personalbar
    139. pkcs11
    140. screen
    141. screenLeft
    142. screenTop
    143. screenX
    144. screenY
    145. scrollbars
    146. scrollMaxX
    147. scrollMaxY
    148. scrollX
    149. scrollY
    150. self
    151. sessionStorage
    152. sidebar
    153. speechSynthesis
    154. status
    155. statusbar
    156. toolbar
    157. top
    158. visualViewport
    159. window
  3. 方法
    1. alert()
    2. atob()
    3. back()
    4. blur()
    5. btoa()
    6. cancelAnimationFrame()
    7. cancelIdleCallback()
    8. captureEvents()
    9. clearImmediate()
    10. clearInterval()
    11. clearTimeout()
    12. close()
    13. confirm()
    14. convertPointFromNodeToPage()
    15. convertPointFromPageToNode
    16. createImageBitmap()
    17. dump()
    18. fetch()
    19. find()
    20. focus()
    21. forward()
    22. getAttention()
    23. getComputedStyle()
    24. getDefaultComputedStyle()
    25. getSelection()
    26. home()
    27. matchMedia()
    28. minimize()
    29. moveBy()
    30. moveTo()
    31. open()
    32. openDialog()
    33. postMessage()
    34. print()
    35. prompt()
    36. queueMicrotask()
    37. releaseEvents()
    38. requestAnimationFrame()
    39. requestFileSystem()
    40. requestIdleCallback()
    41. resizeBy()
    42. resizeTo()
    43. restore()
    44. routeEvent()
    45. scroll()
    46. scrollBy()
    47. scrollByLines()
    48. scrollByPages()
    49. scrollTo()
    50. setCursor()
    51. setImmediate()
    52. setInterval()
    53. setTimeout()
    54. showModalDialog()
    55. sizeToContent()
    56. stop()
    57. updateCommands()
  4. 事件
    1. event
    2. afterprint
    3. beforeprint
    4. beforeunload
    5. blur
    6. copy
    7. cut
    8. DOMContentLoaded
    9. error
    10. focus
    11. hashchange
    12. languagechange
    13. load
    14. message
    15. messageerror
    16. offline
    17. online
    18. orientationchange
    19. pagehide
    20. pageshow
    21. paste
    22. popstate
    23. rejectionhandled
    24. storage
    25. unhandledrejection
    26. unload
    27. vrdisplayconnect
    28. vrdisplaydisconnect
    29. vrdisplaypresentchange