JavaScript Window.closed Property

Window.closed is a read-only Boolean property on a referenced window. It is true when that window is closed and false while it remains open.

if (childWindow && !childWindow.closed) {
  childWindow.focus();
}
On this page

Demo of window.closed Top ↑

DEMO of window.closed

The original page linked to Ajax Message; that related reference is retained. The updated demo itself uses a small inline status region and does not require Ajax.

Complete source code Top ↑

<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Demo of closed window</title></head>
<body>
<button type="button" id="openWindow">Open</button>
<button type="button" id="closeWindow">Close</button>
<button type="button" id="focusWindow">Focus</button>
<button type="button" id="blurWindow">Blur</button>
<p id="msg" hidden></p>
<script>
let childWindow = null;
let hideTimer = null;
const message = document.getElementById('msg');
function showMessage(text) {
  message.textContent = text;
  message.hidden = false;
  clearTimeout(hideTimer);
  hideTimer = setTimeout(() => { message.hidden = true; }, 2000);
}
function isUnavailable() {
  return !childWindow || childWindow.closed;
}
document.getElementById('openWindow').addEventListener('click', () => {
  childWindow = window.open('moveby-child.htm', 'Ratting', 'width=250,height=150,left=150,top=200,status=0');
  showMessage(childWindow ? 'Window is open' : 'Popup blocked. Allow popups and try again.');
});
document.getElementById('closeWindow').addEventListener('click', () => {
  if (isUnavailable()) return showMessage('Window is closed, first open it');
  childWindow.close();
  showMessage('Close requested');
});
document.getElementById('focusWindow').addEventListener('click', () => {
  if (isUnavailable()) return showMessage('Window is closed, first open it');
  childWindow.focus();
  showMessage('Window focus requested');
});
document.getElementById('blurWindow').addEventListener('click', () => {
  if (isUnavailable()) return showMessage('Window is closed, first open it');
  childWindow.blur();
  showMessage('Window blur requested (browser may ignore it)');
});
</script>
</body>
</html>

Popup blocking and null window references Top ↑

Before reading .closed, first make sure a window reference exists. A blocked window.open() call can return null.

const childWindow = window.open("child.htm", "child");
if (!childWindow) {
  console.log("Popup was blocked");
} else if (childWindow.closed) {
  console.log("The child is closed");
}

Focus and blur controls Top ↑

The original demo has Open, Close, Focus and Blur controls, and all four are preserved. Browsers may restrict or ignore focus/blur requests to avoid disruptive window behavior.

Window Focus

Window Object Bookmark a page Redirect Page




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer