Window.closed

Summary

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

Syntax

isClosed = windowRef.closed;
isClosed
A boolean. 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 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() 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.

var 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

HTML5

See also

发布了430 篇原创文章 · 获赞 415 · 访问量 925万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览