Javascript close popup

Discussion in 'Javascript' started by Colin Graham, Apr 28, 2005.

  1. Colin Graham

    Colin Graham Guest

    Hi guys,

    Just a quickie here that i hope someone can help me with. Basically i
    want stop the user from closing the popup window using the small x
    button in the top right hand corner. Im aware that i cant disable this
    so i thought is it possible to do a check to see if a hidden text on
    the main form has a value. E.g. if we close the popup correctly then
    text box on the main form will say true. If we close the text box
    using the x in the right hand corner the text box will say false or
    just be empty and then make the popup reapppear.

    Is this possible and if so would anyone have any example of how i
    would go about this because im pretty useless and new to javascript.

    thanks in advance

    CG
    Colin Graham, Apr 28, 2005
    #1
    1. Advertising

  2. Colin Graham

    Evertjan. Guest

    Colin Graham wrote on 28 apr 2005 in comp.lang.javascript:
    > Just a quickie here that i hope someone can help me with. Basically i
    > want stop the user from closing the popup window using the small x
    > button in the top right hand corner. Im aware that i cant disable this
    > so i thought is it possible to do a check to see if a hidden text on
    > the main form has a value. E.g. if we close the popup correctly then
    > text box on the main form will say true. If we close the text box
    > using the x in the right hand corner the text box will say false or
    > just be empty and then make the popup reapppear.
    >
    > Is this possible and if so would anyone have any example of how i
    > would go about this because im pretty useless and new to javascript.


    If you are pretty useless and new to javascript,
    how do you know this is just a quickie, Colin?

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Apr 28, 2005
    #2
    1. Advertising

  3. Colin Graham

    Stephen Vick Guest

    You could add a window.open in the OnBeforeUnload event of the body to
    open the window. Pretty annoying though.


    -Vick
    Stephen Vick, Apr 28, 2005
    #3
  4. Colin Graham

    Grant Wagner Guest

    "Colin Graham" <> wrote in message
    news:...
    > Hi guys,
    >
    > Just a quickie here that i hope someone can help me with. Basically i
    > want stop the user from closing the popup window using the small x
    > button in the top right hand corner. Im aware that i cant disable this
    > so i thought is it possible to do a check to see if a hidden text on
    > the main form has a value. E.g. if we close the popup correctly then
    > text box on the main form will say true. If we close the text box
    > using the x in the right hand corner the text box will say false or
    > just be empty and then make the popup reapppear.


    Do the reverse. Have the parent test if the child window is still open
    using setInterval(). If the parent detects the child has closed it
    re-spawns the window. The way to stop the cycle is have a "Close" button
    on the child that properly terminates the timer in the parent before
    closing the window.

    <script type="text/javascript">
    window.newWindowHtml = [
    '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">',
    '<html>',
    '<head>',
    '<title>Test</title>',
    '</head>',
    '<body onload="opener.startTimer();">',
    '<a href="#" onclick="opener.stopTimer();window.close();return
    false;">Close</a>',
    '</body>',
    '</html>'
    ].join('\n');
    function openWindow()
    {
    window.w = window.open('javascript:eek:pener.newWindowHtml');
    }
    function startTimer()
    {
    window.timer = setInterval(testWindow, 500);
    }
    function stopTimer()
    {
    if (window.timer)
    {
    clearInterval(window.timer);
    }
    }
    function testWindow()
    {
    if (!w || w.closed)
    {
    openWindow();
    }
    testWindow.toString = function()
    {
    return 'testWindow();';
    }
    }

    openWindow();
    </script>

    REALLY annoying, but it seems to meet your requirements.

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq

    Pretty annoying, but it would work.
    Grant Wagner, Apr 28, 2005
    #4
  5. Stephen Vick wrote:

    > You could add a window.open in the OnBeforeUnload event
    > of the body to open the window. Pretty annoying though.


    And IE only, fortunately.


    PointedEars
    Thomas 'PointedEars' Lahn, May 8, 2005
    #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. dapkniht
    Replies:
    1
    Views:
    1,310
    Eliyahu Goldin
    Mar 8, 2006
  2. Rajesh
    Replies:
    0
    Views:
    506
    Rajesh
    Jul 31, 2007
  3. Iñaki Baz Castillo
    Replies:
    7
    Views:
    807
    Iñaki Baz Castillo
    Jan 12, 2010
  4. Jens Peter Hansen
    Replies:
    7
    Views:
    493
    Randy Webb
    Jun 19, 2004
  5. Replies:
    2
    Views:
    441
Loading...

Share This Page