I Need help on browser close event. I saw a tutorial but it is not working on all browsers. I need a JavaScript solution that works on all browsers. My purpose on that is to delete a PHP session on browser close.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
window.onunloadto find out if a user is leaving a page/closing a window/closing a tab.But there is no way to really find out if a user has left your website. He might still have another tab or window opened.
So your only real solution is to check how much time has passed since the last activity from that user. And if that has to happen live, you could add an ajax-like callback to poll the server every minute or so to be sure that the user still has his window open.