problems detecting a window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dom Nicholas

    problems detecting a window



    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="javas cript">

    var popupwin;
    function NewWindow(mypag e,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,my name,""); popupwin.focus( );
    }

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

    </head>
    <body>
    <button type="button"
    onClick="NewWin dow('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

    #2
    Re: problems detecting a window

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

    -Wagner

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

    Dom Nicholas <nospam2001@tha nks.com> wrote in message news:<3f9d3a58$ 0$198$75868355@ news.frii.net>. ..[color=blue]
    > 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="javas cript">
    >
    > var popupwin;
    > function NewWindow(mypag e,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,my name,""); popupwin.focus( );
    > }
    >
    > else
    > {
    > popupwin.focus( ); // the window exists so just bring it to the top
    > }
    > }
    > </script>
    >
    > </head>
    > <body>
    > <button type="button"
    > onClick="NewWin dow('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![/color]

    Comment

    • DU

      #3
      Re: problems detecting a window

      Dom Nicholas wrote:
      [color=blue]
      >
      > Hi,
      >
      > My question is this : how do I detect from
      > another window which didn't create a new window whether
      > it exists ?[/color]

      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[color=blue]
      > of some sort that hangs around that I can interrogate ?
      >
      > I would like to find a better way of doing the following.[/color]

      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...
      [color=blue]
      > 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.
      >[/color]

      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.
      [color=blue]
      > (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="javas cript">
      >
      > var popupwin;
      > function NewWindow(mypag e,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,my name,""); popupwin.focus( );[/color]

      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.
      [color=blue]
      > }
      >
      > else
      > {
      > popupwin.focus( ); // the window exists so just bring it to the top
      > }
      > }
      > </script>
      >
      > </head>
      > <body>
      > <button type="button"
      > onClick="NewWin dow('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![/color]


      DU
      --
      Javascript and Browser bugs:

      - Resources, help and tips for Netscape 7.x users and Composer
      - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


      Comment

      Working...