Cookies and Windows

Discussion in 'Javascript' started by Duane, Dec 16, 2003.

  1. Duane

    Duane Guest

    Hi ... here is my situation: I am building an application that is
    driven by a main menu. When the user chooses an option from the main
    menu that spawns a new window (or module). From that(or any) module
    window there is a menu where the user can choose to go to or switch to
    any other module. So ... lets say that the main menu has 4 options.
    The user chooses option 1 which will open a new window (replacing the
    main menu). On that new window there is a menu where the user can
    choose another module (which would spawn that module's window) .. and
    so forth.

    The problem is this: Let's say the user has all 4 modules open and
    then chooses from module1 to switch to module2....well that spawns a
    new window instead of just giving module2 focus. I have solved a big
    portion of this using cookies to let me know if the window is already
    open...however, when the user chooses a module window that is already
    open then I am having trouble giving that window focus.

    Pseudo-code is like this and included in an external .js file that is
    loaded by each new page:

    if (getCookie(pageID) == "")
    {
    alert(pageID + ' not open .. will now open');
    setCookie(pageID,'1','','','','');
    if (pageID=='firstone')
    Page1=window.open(page,'','fullscreen');
    else if (pageID=='secondone')
    Page2=window.open(page,'','fullscreen');
    else if (pageID=='thirdone')
    Page3=window.open(page,'','fullscreen');
    }
    else
    {
    alert(pageID + ' already open .. giving focus');
    if (pageID=='firstone')
    Page1.focus();
    else if (pageID=='secondone')
    Page2.focus();
    else if (pageID=='thirdone')
    Page3.focus();
    }

    Now this works until it runs into a page that is already loaded and
    then tells me that "Page1 is null or not an object". I understand why
    this is happening but am not sure how to make the new window objects
    accessable to the other windows.

    Any help would be greatly appreciated.
    Duane, Dec 16, 2003
    #1
    1. Advertising

  2. Duane

    kaeli Guest

    In article <>,
    enlightened us with...
    >
    > The problem is this: Let's say the user has all 4 modules open and
    > then chooses from module1 to switch to module2....well that spawns a
    > new window instead of just giving module2 focus. I have solved a big
    > portion of this using cookies to let me know if the window is already
    > open...however, when the user chooses a module window that is already
    > open then I am having trouble giving that window focus.
    >


    You'd be better off giving the windows handles and checking for those.

    This is mine for a help menu.
    If the window is open, gives it focus and loads the help screen from an
    array that is populated elsewhere in the script. Modify it for your
    needs.
    Tested for NN6+/IE5+. I can't guarantee it works in any other browser.

    <script language="javascript" type="text/javascript">
    var h_window = null;

    function openHelp(screenName)
    {
    if (!h_window || h_window == null || typeof h_window == "undefined" ||
    h_window.closed || !h_window.document)
    h_window = window.open("","Help","height=200,width=
    200,scrollbars=yes,resizable=yes");
    var doc = h_window.document;
    doc.open();
    doc.writeln("<html><head><title>Help</title>");
    doc.writeln("<link rel='stylesheet' type='text/css'
    href='myStylesheet.css'>");
    doc.writeln("</head><body>");
    doc.writeln(h_array[screenName]);
    doc.writeln("</body></html>");
    doc.close();
    h_window.focus();
    return;
    }
    </script>

    --
    --
    ~kaeli~
    She was engaged to a boyfriend with a wooden leg but broke
    it off.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
    kaeli, Dec 16, 2003
    #2
    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. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,484
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,524
    Fredrik Lindner
    Nov 6, 2003
  3. user
    Replies:
    3
    Views:
    661
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  4. archana
    Replies:
    1
    Views:
    505
  5. _Who
    Replies:
    7
    Views:
    2,656
Loading...

Share This Page