0

A little bit ago I asked this question about if a child can get information on its parent. But now I realize that I have a followup question that belongs on its own, rather than in comments: Can Javascript find out if any window is open?

I have a window A which can either be called from window B or window C. However, when I close A, I want certain things in the onUnload only to happen if window C is closed. Now, A may not have been opened by C, so I can't rely on window.opener. Is there any way I can find out information on arbitrary windows? I thought about checking window.opener.location but that still requires that C have been the opener, which it may not have been. The names of all the windows are known, so if I could search by those, I'd be golden.

(as for the why: A is a chat console, B is the main menu, C is the queue monitor. When someone is in the queue monitor, they're marked as available for chat. But to actually chat, they have to load up the chat console to do so. Normally, when you close the chat console, an onUnload tries to mark you unavailable, but I don't want to that to happen if the queue monitor is still open.)

Community
  • 1
  • 1
Andrew
  • 5,095
  • 6
  • 42
  • 48

1 Answers1

0

The only way to be able to do this is if the parent window that launched the child windows remains open throughout the process. Windows with similar "ancestry" can use the common parent as a relay point. Code on the common parent would probably be required (or at least desirable) to assist.

I suppose it's possible for the common parent to hand each child an object with references to other child windows; I can't imagine any reason for that to fail. Of course, that won't help if one child is launched from one incarnation of the main window, and another launched from a separate one. In that case, even though the windows share a domain, they really have no way of finding each other.

Anyway if you have a reference to a window, the .closed property will tell you if it's closed or not.

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • Hrm, but if the common parent (B, the main menu) were closed, then there'd be no way of doing this? – Andrew Jan 24 '11 at 20:27
  • I think that if you give your child windows references to all the other child windows that are open, they'll keep working even if the original pattern goes away. – Pointy Jan 24 '11 at 20:32