Results 1 to 4 of 4

Thread: [ASP ASP.NET PHP JSP CGI]Logging out a user when they close the window

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    [ASP ASP.NET PHP JSP CGI]Logging out a user when they close the window

    **NOTE: This codebank submission is outdated and no longer works with modern browsers**

    A common question on the forums is, if the user closes the browser window, how can they be logged out immediately?

    Here's how. Have the following javascript in your window

    Code:
    <script language="JavaScript">
    
    
     function initUnload()
      {
         var top=self.screenTop;
         if (top>9000) { 
             var settings = 'width=1,height=1,left=1,top=1,toolbar=0,scrollbars=0,status=0'
             window.open("logout.html?close=true","logoutWindow",settings);  
          } else {//:ehh:
             
          }
      }
    
    
      window.onunload = initUnload;
    </script>
    The part in red, logout.html, can be replaced with any server-side scripted page in ASP/PHP/ASP.NET/WhateverFloatsYourBoat. That page should abandon/clear your sessions.

    Keywords:
    Session
    Logout
    Window
    Close
    logging out
    user
    Last edited by mendhak; Apr 27th, 2009 at 11:22 AM.

  2. #2
    Member
    Join Date
    Dec 2004
    Posts
    59

    Re: [ASP ASP.NET PHP JSP CGI]Logging out a user when they close the window

    nice but what if the user using tab browser, opens multiple tabs or open multiple windows, then they close one of the tabs/windows, will they get log out?

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: [ASP ASP.NET PHP JSP CGI]Logging out a user when they close the window

    Only after 20 minutes of inactivity (by default).

  4. #4
    Member
    Join Date
    Mar 2007
    Location
    Pondicherry, India
    Posts
    33

    Re: [ASP ASP.NET PHP JSP CGI]Logging out a user when they close the window

    Hi menthak,
    I am little bit confuse for you code. so user the need to close the logout.html page. or else it will close automatically.. but i tried your code in seperate application the logout.html page is still opened.. Correct me if i am wrong. And what is the meaning of this code
    Code:
     "logout.html?close=true"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width