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

Discussion in 'Javascript' started by FAQ server, Feb 16, 2007.

  1. FAQ server

    FAQ server Guest

    -----------------------------------------------------------------------
    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.
     
    FAQ server, Feb 16, 2007
    #1
    1. Advertising

  2. In comp.lang.javascript message <45d4f406$0$90267$.
    dk>, Fri, 16 Feb 2007 00:00:01, FAQ server <>
    posted:
    >-----------------------------------------------------------------------
    >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.
     
    Dr J R Stockton, Feb 16, 2007
    #2
    1. Advertising

  3. FAQ server

    -Lost Guest

    Re: FAQ Topic - How do I check to see if a childwindow is open, beforeopening another?

    Dr J R Stockton wrote:
    > In comp.lang.javascript message <45d4f406$0$90267$.


    > 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.
     
    -Lost, Apr 24, 2007
    #3
  4. FAQ server

    -Lost Guest

    Re: FAQ Topic - How do I check to see if a childwindow is open, beforeopening another?

    Randy Webb wrote:
    > -Lost said the following on 4/24/2007 2:23 AM:
    >> Dr J R Stockton wrote:
    >>> In comp.lang.javascript message <45d4f406$0$90267$.

    >>
    >> > 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.
    >
    >> The only way I can think of offhand to do this would be to:

    >
    > It won't work.
    >
    >> 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.
     
    -Lost, Apr 24, 2007
    #4
  5. In comp.lang.javascript message <L6ydnXzbxfz81rPbnZ2dnUVZ_ruknZ2d@comcas
    t.com>, Tue, 24 Apr 2007 14:25:14, -Lost <>
    posted:
    >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.

    --
    (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.
     
    Dr J R Stockton, Apr 25, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. drupel
    Replies:
    1
    Views:
    167
  2. FAQ server
    Replies:
    2
    Views:
    90
    Dr John Stockton
    Sep 30, 2006
  3. FAQ server
    Replies:
    24
    Views:
    237
    Dr J R Stockton
    Dec 29, 2006
  4. FAQ server
    Replies:
    1
    Views:
    226
    Dr J R Stockton
    Oct 16, 2008
  5. FAQ server
    Replies:
    0
    Views:
    83
    FAQ server
    Jul 1, 2009
Loading...

Share This Page