FAQ Topic - How do I check to see if a childwindow is open, before opening another?

F

FAQ server

-----------------------------------------------------------------------
FAQ Topic - How do I check to see if a childwindow is
open, before opening another?
-----------------------------------------------------------------------

var myWin=null;
function openWin(aURL) {
if (!myWin || myWin.closed ) {
myWin=window.open(aURL,'myWin');
} else{
myWin.location=aURL;
myWin.focus();
}
}

http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/closed.asp

http://docs.sun.com/source/816-6408-10/window.htm#1201877


===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
The FAQ workers are a group of volunteers.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected].
-----------------------------------------------------------------------
FAQ Topic - How do I check to see if a childwindow is
open, before opening another?
-----------------------------------------------------------------------

var myWin=null;
function openWin(aURL) {
if (!myWin || myWin.closed ) {
myWin=window.open(aURL,'myWin');
} else{
myWin.location=aURL;
myWin.focus();
}
}

The code, which is accompanied only by links, answers the question "How
do I check to see if the specific childwindow 'myWin' exists and is
open, open it if it exists and is closed, and otherwise create and
focus it ?", which is a different question. Either the question or the
answer should be changed.

I suppose there should be a way of enumerating childwindows; then one
can test to see which are open and which are not.
 
L

-Lost

Dr said:
In comp.lang.javascript message <[email protected].
I suppose there should be a way of enumerating childwindows; then one
can test to see which are open and which are not.

Is there any standard way of doing this?

The only way I can think of offhand to do this would be to:

create your child windows
iterate the parent.window
check for like-named variables, e.g. childWin1, childWin2,
childWinDisplayResults, childWinError

I imagine using a RegExp might be the best method. I am not sure
whether or not creating one long string then using slice, indexOf,
lastIndexOf or substring or whatever, would be faster.

I normally get no more than 90 to 125 lines of properties, objects,
variables, default methods, defined methods, et cetera, if that makes
any difference.

Any ideas?
 
L

-Lost

Randy said:
-Lost said the following on 4/24/2007 2:23 AM:

It won't work.


Sure. Are you just bored or do you have some reason for replying to
months old posts on a regular basis?

Sorry about that. I guess its boredom. I spend quite a bit of time
perusing the archives when I cannot sleep.

I saw this and liked the idea proposed by Stockton so I figured respond
to it in the hopes of getting some good ideas/code out of it.

I'll refrain from further FAQ replies and older posts. Sorry.
 
D

Dr J R Stockton

In comp.lang.javascript message <L6ydnXzbxfz81rPbnZ2dnUVZ_ruknZ2d@comcas
Randy Webb wrote:
I'll refrain from further FAQ replies and older posts. Sorry.

If you configure your attribution line to include the date of what you
are quoting, we will easily see the age of the previous article. That
will be helpful - though one should only respond to ancient articles if
the response will be useful now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top