SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: onClose event

  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2005
    Posts
    527
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onClose event

    Hi

    How can I run a function before user close the browser that work in IE and FF

  2. #2
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is not any onclose event. What are you trying to do? Perhaps here is a better way.

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2005
    Posts
    527
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Daniel0 View Post
    There is not any onclose event. What are you trying to do? Perhaps here is a better way.

    I want make user logoff when close the browser in my messenger

  4. #4
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm... you could poll the server using AJAX and if you haven't received a response in, say 15 seconds then you would assume the user has left. You could also use onUnload, but that would also trigger when the user reloads the page or goes to another page. I'm not sure if you want that.

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you maintain login state with cookies, setting a cookie with no expiration time is handled by browsers as "keep cookie until all of my windows are closed, even if those windows arent for the same site". This is commonly called a session cookie.

    You could also put some serverside logic which will deny the login state if the last activity is more than x minutes ago.


Bookmarks

Posting Permissions

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