Javascript close popup

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Colin Graham

    #1

    Javascript close popup

    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
  • Evertjan.

    #2
    Re: Javascript close popup

    Colin Graham wrote on 28 apr 2005 in comp.lang.javas cript:[color=blue]
    > 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.[/color]

    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)

    Comment

    • Stephen Vick

      #3
      Re: Javascript close popup

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


      -Vick

      Comment

      • Grant Wagner

        #4
        Re: Javascript close popup

        "Colin Graham" <csgraham74@hot mail.com> wrote in message
        news:ee261922.0 504280134.5bf02 128@posting.goo gle.com...[color=blue]
        > 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.[/color]

        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.newWindo wHtml = [
        '<!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();wi ndow.close();re turn
        false;">Close</a>',
        '</body>',
        '</html>'
        ].join('\n');
        function openWindow()
        {
        window.w = window.open('ja vascript:opener .newWindowHtml' );
        }
        function startTimer()
        {
        window.timer = setInterval(tes tWindow, 500);
        }
        function stopTimer()
        {
        if (window.timer)
        {
        clearInterval(w indow.timer);
        }
        }
        function testWindow()
        {
        if (!w || w.closed)
        {
        openWindow();
        }
        testWindow.toSt ring = function()
        {
        return 'testWindow();' ;
        }
        }

        openWindow();
        </script>

        REALLY annoying, but it seems to meet your requirements.

        --
        Grant Wagner <gwagner@agrico reunited.com>
        comp.lang.javas cript FAQ - http://jibbering.com/faq

        Pretty annoying, but it would work.


        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Javascript close popup

          Stephen Vick wrote:
          [color=blue]
          > You could add a window.open in the OnBeforeUnload event
          > of the body to open the window. Pretty annoying though.[/color]

          And IE only, fortunately.


          PointedEars

          Comment

          Working...