Connecting Tech Pros Worldwide Forums | Help | Site Map

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

FAQ server
Guest
 
Posts: n/a
#1: Feb 16 '07
-----------------------------------------------------------------------
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/a...ies/closed.asp

http://docs.sun.com/source/816-6408-...ow.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.


Dr J R Stockton
Guest
 
Posts: n/a
#2: Feb 16 '07

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


In comp.lang.javascript message <45d4f406$0$90267$14726298@news.sunsite.
dk>, Fri, 16 Feb 2007 00:00:01, FAQ server <javascript@dotinternet.be>
posted:
Quote:
>-----------------------------------------------------------------------
>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.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20 ; WinXP.
Web <URL:http://www.merlyn.demon.co.uk/- FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm- also batprogs.htm.
-Lost
Guest
 
Posts: n/a
#3: Apr 24 '07

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


Dr J R Stockton wrote:
Quote:
In comp.lang.javascript message <45d4f406$0$90267$14726298@news.sunsite.
Quote:
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?

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Randy Webb
Guest
 
Posts: n/a
#4: Apr 24 '07

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


-Lost said the following on 4/24/2007 2:23 AM:
Quote:
Dr J R Stockton wrote:
Quote:
>In comp.lang.javascript message <45d4f406$0$90267$14726298@news.sunsite.
>
Quote:
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?
No.
Quote:
The only way I can think of offhand to do this would be to:
It won't work.
Quote:
Any ideas?
Sure. Are you just bored or do you have some reason for replying to
months old posts on a regular basis?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
-Lost
Guest
 
Posts: n/a
#5: Apr 24 '07

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


Randy Webb wrote:
Quote:
-Lost said the following on 4/24/2007 2:23 AM:
Quote:
>Dr J R Stockton wrote:
Quote:
>>In comp.lang.javascript message <45d4f406$0$90267$14726298@news.sunsite.
>>
Quote:
> 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?
>
No.
>
Quote:
>The only way I can think of offhand to do this would be to:
>
It won't work.
>
Quote:
>Any ideas?
>
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.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Randy Webb
Guest
 
Posts: n/a
#6: Apr 24 '07

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


-Lost said the following on 4/24/2007 2:25 PM:
Quote:
Randy Webb wrote:
Quote:
>-Lost said the following on 4/24/2007 2:23 AM:
Quote:
>>Dr J R Stockton wrote:
>>>In comp.lang.javascript message
>>><45d4f406$0$90267$14726298@news.sunsite.
>>>
>> 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?
>>
>No.
>>
Quote:
>>The only way I can think of offhand to do this would be to:
>>
>It won't work.
>>
Quote:
>>Any ideas?
>>
>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.
No problem with that, I was just curious more than anything else.
Quote:
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.
The idea (both yours and his) has a little merit but not a lot as it may
not even be your code that created the window. You could try going
through all non-native properties of the window object and testing them
but I doubt you could ever find a sufficient test to tell you if myVar
referred to a new window or not.
Quote:
I'll refrain from further FAQ replies and older posts. Sorry.
Nah, post away. It kills the boredom.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dr J R Stockton
Guest
 
Posts: n/a
#7: Apr 25 '07

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


In comp.lang.javascript message <L6ydnXzbxfz81rPbnZ2dnUVZ_ruknZ2d@comcas
t.com>, Tue, 24 Apr 2007 14:25:14, -Lost <maventheextrawords@techie.com>
posted:
Quote:
>Randy Webb wrote:
Quote:
>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.

--
(c) John Stockton, Surrey, UK. REPLYyyww merlyn demon co uk Turnpike 6.05.
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm: about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
Closed Thread