Window Close

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SanthuBalu
    New Member
    • Mar 2007
    • 4

    Window Close

    Hi Friends,
    I have a problem for logout operation. whenever i close the browser of my application, I should indicate that the user has logged out without clicking the logout button.. I hav written a function on window close. The problem is that function is called for each time when i make a navigation to another window in my application.

    Please help me how to solve this problem.
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    r u using window.onbefore unload = function_ref ?????????

    if possible plz send ur code so that i can understand what u r using .....

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by SanthuBalu
      Hi Friends,
      I have a problem for logout operation. whenever i close the browser of my application, I should indicate that the user has logged out without clicking the logout button.. I hav written a function on window close. The problem is that function is called for each time when i make a navigation to another window in my application.

      Please help me how to solve this problem.
      You don't need to inform the user that they have been logged out. If they close the window, they've logged themselves out (as long as you've coded that), or maybe there's a timeout after which they'll be logged out.

      Comment

      • prasadsurya
        New Member
        • Mar 2007
        • 3

        #4
        Originally posted by SanthuBalu
        Hi Friends,
        I have a problem for logout operation. whenever i close the browser of my application, I should indicate that the user has logged out without clicking the logout button.. I hav written a function on window close. The problem is that function is called for each time when i make a navigation to another window in my application.

        Please help me how to solve this problem.
        <html>
        <head>
        <script type="text/javascript">
        var myclose = false;
        function ConfirmClose()
        {
        if (event.clientY < 0)
        {
        myclose = true;
        }
        }
        function HandleOnClose()
        {
        if (myclose==true)
        {
        window.open('ht tp://www.google.com' );
        }
        }
        </script>
        </HEAD>
        <body topmargin='0' bottommargin='0 ' leftmargin='20' rightmargin='20 ' onbeforeunload= "ConfirmClose() " onunload="Handl eOnClose()">
        </body>
        </html>

        Comment

        • SanthuBalu
          New Member
          • Mar 2007
          • 4

          #5
          Hi friends,
          Thanx for ur timely help. It works well.
          I found another solution to check whether the close button is clicked or not regardless of whether the browser is maximised or minimised.
          it goes like this.......

          //To check whether the user has clicked on the close button on top of window
          function initUnload()
          {
          var top=self.screen Top;
          //alert ("top"+top);
          if (top>9000)
          {

          alert("Window is closed!!!!!!");
          }
          else if (top<0)
          {
          // check whether the user has minimised the window and closed it using right click options.

          alert("Window is closed!!!!!!");

          }
          }


          window.onunload = initUnload;

          Comment

          • Kedar Patil
            New Member
            • Mar 2007
            • 1

            #6
            OnUnload works only in IE
            wh about other browser - NN, Mozilla, Opera

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by Kedar Patil
              OnUnload works only in IE
              wh about other browser - NN, Mozilla, Opera
              onunload works in IE, FF, Netscape, Safari. Only Opera doesn't support it properly. See link and the famous event compatibility tables.

              Comment

              • gauravgmbhr
                New Member
                • Feb 2007
                • 107

                #8
                Originally posted by SanthuBalu
                Hi Friends,
                I have a problem for logout operation. whenever i close the browser of my application, I should indicate that the user has logged out without clicking the logout button.. I hav written a function on window close. The problem is that function is called for each time when i make a navigation to another window in my application.

                Please help me how to solve this problem.

                Send Ur code
                wat u did
                in order to get solution from the comminity members

                Comment

                • hini
                  New Member
                  • Mar 2007
                  • 23

                  #9
                  I faced the problem before but could not resolve it,
                  I searched for a javascript function to send a request to server page when the window is closed, and I tried onUnload.
                  the problem with onUnload is that it is executed even if I try to refresh the page.

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Originally posted by hini
                    I faced the problem before but could not resolve it,
                    I searched for a javascript function to send a request to server page when the window is closed, and I tried onUnload.
                    the problem with onUnload is that it is executed even if I try to refresh the page.
                    You can use self.screenTop as suggested earlier, but I don't think it's supported by all browsers.

                    Comment

                    • Masouddotnet
                      New Member
                      • Mar 2007
                      • 6

                      #11
                      sorry me but it is not the good way

                      you have much bugs in this way!!!

                      You can write an script(ASP/ASP.Net/...) that chek your user that is in your web application or not!

                      that is not good!!!!

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Originally posted by Masouddotnet
                        sorry me but it is not the good way

                        you have much bugs in this way!!!

                        You can write an script(ASP/ASP.Net/...) that chek your user that is in your web application or not!

                        that is not good!!!!
                        True. Logouts should be dealt with on the server side. If the user closes the browser, let them. Log them out automatically using sessions if there's a period of inactivity, say 30 minutes. Then you don't have to worry about detecting if the user has closed the browser.

                        Comment

                        Working...