problems detecting a window

Discussion in 'Javascript' started by Dom Nicholas, Oct 27, 2003.

  1. Dom Nicholas

    Dom Nicholas Guest

    Hi,

    My question is this : how do I detect from
    another window which didn't create a new window whether
    it exists ? For example, is there a window-id's container
    of some sort that hangs around that I can interrogate ?

    I would like to find a better way of doing the following.
    I have a window (call it Win) that creates a new window (call it Win2)
    using window.open().
    It detects if the window already exists and brings it to the front if it
    does (else it just creates it). That works fine within the creator
    window Win.

    The problem occurs when I reload window Win and hit the create-window
    button. The Win2 window is reset and reloads
    from scratch. I want it to just be brought to the top.

    (Context :In my work what I do is have the Order button bring up an
    order form from an item page. Then going to another item page hitting
    order should not reload the order form since then all the previous item
    orders are thrown away - I just raise it to the top if its hidden.)


    ok thanks for any help.


    here's the code :

    <html>
    <head>
    <script language="javascript">

    var popupwin;
    function NewWindow(mypage,myname)
    {

    if ( popupwin==null || popupwin.closed ) // the window doesn't exist
    or is closed so create it and bring it to the top
    {
    popupwin=window.open(mypage,myname,""); popupwin.focus();
    }

    else
    {
    popupwin.focus(); // the window exists so just bring it to the top
    }
    }
    </script>

    </head>
    <body>
    <button type="button"
    onClick="NewWindow('http://www.google.com','orderform')" >Order
    </button>
    </body></html>

    -Dom


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Dom Nicholas, Oct 27, 2003
    #1
    1. Advertising

  2. Dom Nicholas

    W d'Anjos Guest

    Give the following code a try, it worked for me on IE6 and NS7.

    -Wagner

    <html>
    <head>
    <script language="javascript">
    var popupwin;
    function NewWindow(mypage,myname)
    {
    if ( !popupwin || popupwin.closed ){
    popupwin=window.open("",myname,"");
    try{
    popupwin.location.href; // throws exception if after reload
    popupwin.location = mypage;
    }catch(e){};
    }
    popupwin.focus();
    }
    </script>
    </head>
    <body>
    <button type="button"
    onClick="NewWindow('http://www.google.com','orderform')" >Order
    </button>
    </body></html>

    Dom Nicholas <> wrote in message news:<3f9d3a58$0$198$>...
    > Hi,
    >
    > My question is this : how do I detect from
    > another window which didn't create a new window whether
    > it exists ? For example, is there a window-id's container
    > of some sort that hangs around that I can interrogate ?
    >
    > I would like to find a better way of doing the following.
    > I have a window (call it Win) that creates a new window (call it Win2)
    > using window.open().
    > It detects if the window already exists and brings it to the front if it
    > does (else it just creates it). That works fine within the creator
    > window Win.
    >
    > The problem occurs when I reload window Win and hit the create-window
    > button. The Win2 window is reset and reloads
    > from scratch. I want it to just be brought to the top.
    >
    > (Context :In my work what I do is have the Order button bring up an
    > order form from an item page. Then going to another item page hitting
    > order should not reload the order form since then all the previous item
    > orders are thrown away - I just raise it to the top if its hidden.)
    >
    >
    > ok thanks for any help.
    >
    >
    > here's the code :
    >
    > <html>
    > <head>
    > <script language="javascript">
    >
    > var popupwin;
    > function NewWindow(mypage,myname)
    > {
    >
    > if ( popupwin==null || popupwin.closed ) // the window doesn't exist
    > or is closed so create it and bring it to the top
    > {
    > popupwin=window.open(mypage,myname,""); popupwin.focus();
    > }
    >
    > else
    > {
    > popupwin.focus(); // the window exists so just bring it to the top
    > }
    > }
    > </script>
    >
    > </head>
    > <body>
    > <button type="button"
    > onClick="NewWindow('http://www.google.com','orderform')" >Order
    > </button>
    > </body></html>
    >
    > -Dom
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    W d'Anjos, Oct 27, 2003
    #2
    1. Advertising

  3. Dom Nicholas

    DU Guest

    Dom Nicholas wrote:

    >
    > Hi,
    >
    > My question is this : how do I detect from
    > another window which didn't create a new window whether
    > it exists ?


    Not possible in a default security environment. Just imagine if it was
    possible: it would lead to abuse on the web.
    Not recommendable either. You might be reloading an entirely different
    opener window: why should its previously related sub-window, secondary
    window be the same as the previous opener?

    For example, is there a window-id's container
    > of some sort that hangs around that I can interrogate ?
    >
    > I would like to find a better way of doing the following.


    Now, this is what is most likely the proper way to present your problem.
    You need to explain your website, webpage context; what you really want
    to do, what your webpage is about, webpage requirements, etc...

    > I have a window (call it Win) that creates a new window (call it Win2)
    > using window.open().
    > It detects if the window already exists and brings it to the front if it
    > does (else it just creates it). That works fine within the creator
    > window Win.
    >
    > The problem occurs when I reload window Win and hit the create-window
    > button. The Win2 window is reset and reloads
    > from scratch. I want it to just be brought to the top.
    >


    The pointer stored by the opener, regarding the opener to the child
    window is lost when the opener is entirely reloaded.
    What you're explaining is one limitation and one constraint (among many
    others) regarding secondary windows. That's just one reason why
    requested popup windows is usually (I didn't say always) not recommendable.

    > (Context :In my work what I do is have the Order button bring up an
    > order form from an item page. Then going to another item page hitting
    > order should not reload the order form since then all the previous item
    > orders are thrown away - I just raise it to the top if its hidden.)
    >
    >
    > ok thanks for any help.
    >
    >
    > here's the code :
    >
    > <html>
    > <head>
    > <script language="javascript">
    >
    > var popupwin;
    > function NewWindow(mypage,myname)
    > {
    >
    > if ( popupwin==null || popupwin.closed ) // the window doesn't exist
    > or is closed so create it and bring it to the top
    > {
    > popupwin=window.open(mypage,myname,""); popupwin.focus();


    This popupwin.focus() call in that previous line is illogical, at least
    redundant. If the requested popup window is not existing or is closed,
    then create it and give it focus. There is no need to bring it on top
    since the instruction creates it.

    > }
    >
    > else
    > {
    > popupwin.focus(); // the window exists so just bring it to the top
    > }
    > }
    > </script>
    >
    > </head>
    > <body>
    > <button type="button"
    > onClick="NewWindow('http://www.google.com','orderform')" >Order
    > </button>
    > </body></html>
    >
    > -Dom
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!



    DU
    --
    Javascript and Browser bugs:
    http://www10.brinkster.com/doctorunclear/
    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
    http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
     
    DU, Oct 28, 2003
    #3
    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. Andrew Bewley via DotNetMonster.com

    window to window communication (window.opener)

    Andrew Bewley via DotNetMonster.com, Feb 3, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,055
    Andrew Bewley via DotNetMonster.com
    Feb 3, 2005
  2. Peter TB Brett

    Detecting window focus events in PyGTK

    Peter TB Brett, Aug 28, 2006, in forum: Python
    Replies:
    0
    Views:
    499
    Peter TB Brett
    Aug 28, 2006
  3. Dom Nicholas

    detecting a window from another window

    Dom Nicholas, Oct 27, 2003, in forum: Javascript
    Replies:
    0
    Views:
    74
    Dom Nicholas
    Oct 27, 2003
  4. Robert Dickow

    Detecting closed parent window from popup

    Robert Dickow, Nov 30, 2003, in forum: Javascript
    Replies:
    1
    Views:
    258
    Fabian
    Nov 30, 2003
  5. Replies:
    3
    Views:
    111
Loading...

Share This Page