window closing event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pshm
    New Member
    • Mar 2008
    • 20

    window closing event

    how to handle window closing event in javascript???

    [code=javascript] window.onunload =function(){
    if(window.event .clientY < 0 && window.event.cl ientY < -80){
    alert('window close event triggered');
    }
    }[/code]
    this is working bassed on the mouse cursor.. in some case its not working... is there any alternate way to solve this prob??????
    Regards,
    Prakash M.
    Last edited by gits; Mar 24 '08, 12:35 PM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    the unload and onbeforeunload events will always be triggered when you leave the page and they have no corresponding event source ...

    is it a popup window or the main browser window where you need a handling?

    kind regards

    Comment

    • pshm
      New Member
      • Mar 2008
      • 20

      #3
      Originally posted by gits
      the unload and onbeforeunload events will always be triggered when you leave the page and they have no corresponding event source ...

      is it a popup window or the main browser window where you need a handling?

      kind regards
      hi,
      thanks for reply. I need this in main window.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        hmm ... in this case you could just use onbeforeunload/onunload to call a js-function to do something when the user navigates away from your page ... there is no real/reliable posibility to capture the close-event of the main window ...

        popup windows have a close-property that you might ask for and there you could check for it ...

        kind regards

        Comment

        • pshm
          New Member
          • Mar 2008
          • 20

          #5
          ya i knew for the popup...
          in main window closing i need to clear some flags which was set while loading for that only im trying...

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            Originally posted by pshm
            ya i knew for the popup...
            in main window closing i need to clear some flags which was set while loading for that only im trying...
            hi ...

            are the flags javascript-variables? aren't they cleared anytime you leave the page?

            kind regards

            Comment

            • pshm
              New Member
              • Mar 2008
              • 20

              #7
              hi,
              they are not javascript flags.
              the flags belongs to database(SQL server2005).
              in my project if any user logged into the system the flag will become true to that corrspond user.this i did in the page_load event.
              if the user logged out the flag will be reset to false.
              unfortunately if the user close the window without logging out the flages in the DB remains the same.The next time he can't login to the page.
              i tried in unload and onbeforeunload for every time the page gets postback these events are getting triggered.

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                typically you may use a session or a cookie for such purposes. everytime the user performs an action you update a timestamp and when he doesn't do something for a certain amount of time you just log him out and he has to login again ...

                kind regards

                Comment

                • pshm
                  New Member
                  • Mar 2008
                  • 20

                  #9
                  Originally posted by gits
                  typically you may use a session or a cookie for such purposes. everytime the user performs an action you update a timestamp and when he doesn't do something for a certain amount of time you just log him out and he has to login again ...

                  kind regards
                  ya im using session. by default 20min. if the user doesn't have intraction for 20min the session will be expired, after 20min if he click on some controls it will be redirected to login screen there im clearing the flag in the DB.but the major issue is when he click the close button the session will automatically gets cleared by the browser but the userflag remains same in the DB.

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    if a user is trying to login why don't you always reset the flag first and clear the session in case he has one? or use a mechanism that resets the flag when there is a 'good' time for it ... may be you retrieve the logged in users sometimes ... with that process reset all userflags where no corresponding session is found ... that could be done for example when the login-page loads?

                    Comment

                    • pshm
                      New Member
                      • Mar 2008
                      • 20

                      #11
                      hi,
                      do you know about asp.net
                      in this one event handler is there for handling the application_end event
                      Code:
                      void Application_End(object sender, EventArgs e) 
                          {
                              //  Code that runs on application shutdown     
                          }
                      but its not getting triggered properly.

                      Comment

                      • gits
                        Recognized Expert Moderator Expert
                        • May 2007
                        • 5390

                        #12
                        Originally posted by pshm
                        hi,
                        do you know about asp.net
                        in this one event handler is there for handling the application_end event
                        Code:
                        void Application_End(object sender, EventArgs e) 
                            {
                                //  Code that runs on application shutdown     
                            }
                        but its not getting triggered properly.
                        unfortunatly i'm not familiar with asp.net ... i would suggest that you would ask the question in the .NET forum ...

                        kind regards

                        Comment

                        • pshm
                          New Member
                          • Mar 2008
                          • 20

                          #13
                          Originally posted by gits
                          unfortunatly i'm not familiar with asp.net ... i would suggest that you would ask the question in the .NET forum ...

                          kind regards
                          i tried with that only. i didn't get. so that only came to javascript.
                          ok thank you for spent time to my query

                          kind regards,
                          Prakash:)

                          Comment

                          Working...