update status when closing browser window

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paulrajj
    New Member
    • Sep 2008
    • 47

    #1

    update status when closing browser window

    Hi,

    I am working on my project which is a chat online script using php and javascript. I am maintaining users online_status who gets logged in to chat through session and updating their status to 'yes' in table. I am showing users online through one link which is "Show users online".

    When user logged in for chatting I updated the online_status to 'yes' and when user logged out i changed the status to 'No'. But my problem here is when user logged in, and closed the browser with out clicking logged out, I cant able to unset their sessions and cant able to find that users and updated their online_status to 'No'.

    I tried with window.onbefore unload and ajax functions but its failed. using onbeforeupload function whenever i clicked any link in my page this event gets called once. but i need to call this function only when user closing the browser window. Below is my sample script using onbeforeunload,

    Code:
    window.onbeforeunload = function() {
      alert("You have chosen to close this window");
    }
    I want to update the status and clear the sessions when user closing the browser without loggedout.

    Any suggestions greatly appreciated.
  • pradeepkr13
    New Member
    • Aug 2010
    • 43

    #2
    Use cookie.
    cookie,if created with no expiration date property, will be deleted automatically when the browser closed.
    Browser closed checking could be done on server side.
    But, we have to check the existences of cookie with specific name on server.

    Comment

    Working...