Online Shopping : Computers : Programming : Languages : JavaScript : Windows

+ Search
Add Entry AlertManage Folder Edit Entry Add page to
Did You Find This Entry Useful?

105 of 124 people (85%) answered Yes
Recently 9 of 10 people (90%) answered Yes


Is there a browser wide windows array?
Are windows globally accessible?
How to check whether a named window already exists?

Sep 17th, 2004 11:42
Daniel LaLiberte, J Carty, Martin Honnen,

Client side JavaScript distinguishes windows by their name, so ('url', 'windowName')
opens a window with its name property ( set to 'windowName'.
You can also set the name for an already open window which is useful 
for windows not opened by JavaScript which need to be targetted by a 
link or form.  E.g. = 'myWindowName'
There is, however, no browser wide/global array of all existing windows 
(possibly for security reasons I think). Thus you can't check whether a 
window with a certain name already exists.  The closest thing you can 
do is call open with an empty url and then test what you get.
  var win = ('', 'windowName')
If the window with that name already exists, win will contain the 
window which you can then look inside and operate on, if access is 
permitted.  E.g. if (win.myStuff) alert ('must be my window').  
Otherwise, if the window doesn't exist, will create a new 
What you could also do, if you can avoid refreshing your window, is 
create an array and put each of the windows you create into the array 
and reference them like that.
var windowsArray = new Array();
windowsArray[] =, title, windowfeatures);
That should work fine. I've used it in an instant messaging client to 
close all the windows.
Example of closing all the windows:
  if((windowsArray[i]) && (!windowsArray[i].closed)