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,
I want to update the status and clear the sessions when user closing the browser without loggedout.
Any suggestions greatly appreciated.
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");
}
Any suggestions greatly appreciated.
Comment