Popup Window Detection and Close Button Activation

Discussion in 'Javascript' started by andrewkooi, Aug 31, 2004.

  1. andrewkooi

    andrewkooi Guest

    Greetings,

    I do not know whether such code exist but no harm asking:

    Is it possible for me to make visible a close button if the active
    window is a popup window or a new window (other than the main window)?

    What I mean is this:

    If the present window is the main window, then the close button should
    not be visible on the page. Otherwise, the close button should be made
    visible and active (i.e. can be clicked to close the window).

    Any help is much appreciated.
     
    andrewkooi, Aug 31, 2004
    #1
    1. Advertising

  2. andrewkooi

    rf Guest

    andrewkooi wrote

    > Is it possible for me to make visible a close button if the active
    > window is a popup window or a new window (other than the main window)?


    All windows have a "close" button anyway. That X that the top right.

    --
    Cheers
    Richard.
     
    rf, Aug 31, 2004
    #2
    1. Advertising

  3. andrewkooi

    ZER0 Guest

    On 31 Aug 2004 01:47:06 -0700, andrewkooi wrote:

    > Is it possible for me to make visible a close button if the active
    > window is a popup window or a new window (other than the main window)?


    Check opener property of the current window.

    for example:

    <script type="text/javascript">
    window.onload=function(){
    if (window.opener)
    document.getElementById("btnClose").style.visibility="visible";
    }
    </script>

    --
    ZER0://coder.gfxer.web-designer/

    ~ Io non soffro di pazzia, ne godo ogni minuto.
    (I don't suffer from insanity, I enjoy every minute of it)

    on air ~ "Ligabue - Ho Messo Via"
     
    ZER0, Aug 31, 2004
    #3
  4. andrewkooi

    Mick White Guest

    rf wrote:

    > andrewkooi wrote
    >
    >
    >>Is it possible for me to make visible a close button if the active
    >>window is a popup window or a new window (other than the main window)?

    >
    >
    > All windows have a "close" button anyway. That X that the top right.
    >

    Or a red circle top left....
    Mac OSX
    Mick
     
    Mick White, Aug 31, 2004
    #4
  5. andrewkooi

    andrewkooi Guest

    Greetings,

    > <script type="text/javascript">
    > window.onload=function(){
    > if (window.opener)
    > document.getElementById("btnClose").style.visibility="visible";
    > }
    > </script>


    This code appeared to work fine in IE6 but does not work in NS7, or
    even the latest versions of Opera and Mozilla. Any ideas how to
    resolve this?

    Thanx.
     
    andrewkooi, Sep 1, 2004
    #5
  6. andrewkooi

    ZER0 Guest

    On 1 Sep 2004 05:48:38 -0700, andrewkooi wrote:

    > This code appeared to work fine in IE6 but does not work in NS7, or
    > even the latest versions of Opera and Mozilla.


    This code works also in gecko-based browser (my default browser is not IE
    but Firefox).
    Try this page, for example:

    <html>
    <head>
    <title>Untitled</title>
    <style type="text/css">
    #btnClose{margin-top:8px;display:block;visibility:hidden;}
    </style>
    <script type="text/javascript">
    window.onload=function(){
    if (window.opener)
    document.getElementById("btnClose").style.visibility="visible";
    }
    </script>
    </head>

    <body>

    <button onclick="window.open(window.location.href)">open a popup</button>

    <button id="btnClose" onclick="window.close()">you are in a
    <strong>popup</strong> window.<br />Click this button to close.</button>

    </body>
    </html>

    (tested on FF)

    --
    ZER0://coder.gfxer.web-designer/

    ~ "Rispetto e' Memoria, non Oblio."
     
    ZER0, Sep 1, 2004
    #6
  7. andrewkooi wrote:

    > Is it possible for me to make visible a close button if the active
    > window is a popup window or a new window (other than the main window)?


    You asked that a few hours before, and my answer is still the same.
    It is inappropriate to re-post within such a short amount of time
    only because no one replied to date. Especially on Google Groups
    postings take time to be archived, since it is only an archive of
    Usenet postings.


    PointedEars
    --
    All I asked for was a simple rotating chair! Throw me a frickin' bone here!
     
    Thomas 'PointedEars' Lahn, Sep 4, 2004
    #7
    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. Marine
    Replies:
    3
    Views:
    23,769
    Marine
    Feb 15, 2006
  2. Jens Peter Hansen
    Replies:
    7
    Views:
    593
    Randy Webb
    Jun 19, 2004
  3. andrewkooi
    Replies:
    2
    Views:
    107
    Thomas 'PointedEars' Lahn
    Sep 4, 2004
  4. Sujan
    Replies:
    6
    Views:
    168
    Sujan
    Jun 25, 2005
  5. Shang Wenbin

    close current window using window.close()

    Shang Wenbin, Sep 1, 2005, in forum: Javascript
    Replies:
    10
    Views:
    422
    GĂ©rard Talbot
    Sep 2, 2005
Loading...

Share This Page