473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

update status when closing browser window

paulrajj
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.onbeforeunload 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,

Expand|Select|Wrap|Line Numbers
  1. window.onbeforeunload = function() {
  2.   alert("You have chosen to close this window");
  3. }
  4.  
I want to update the status and clear the sessions when user closing the browser without loggedout.

Any suggestions greatly appreciated.
Aug 13 '10 #1
1 2365
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.
Aug 24 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike May | last post by:
Hi IE6 Win2k The javascript FAQ describes how you can retain a reference to a window that you have opened and manipulate the window - focus on it or close it, viz: 4.10 How do I check to...
11
by: David Lozzi | last post by:
Hello All, I am having an issue with thus far one computer on my client's web site. If the user loads the shopping cart and then closes all browser windows, then opens them back up, goes back to...
4
by: DM | last post by:
Is there any way, using a server control, to execute a routine (say, add record to database) and then close the browser window. I'm having a difficult time doing this using a master\detail model...
3
by: Sileesh | last post by:
Hi I hope some one has an answer to this. I have a button in an aspx page . On server click of this button, i perform some operation. Once the operation is performed i want to close this...
8
by: sun | last post by:
I want to do clean up routine to my database when the browser is closed. I have my code in session-end - but it never fires when the browser closes. I cant do onbeforeunload as it will be fired...
2
by: Tom | last post by:
How is the best way to avoid validation when closing a window? For instance, I have a Windows Forms window which has a validation event for a text box. However, if one enters invalid data in then...
3
by: =?Utf-8?B?Vk1J?= | last post by:
How can I close popup window automatically when I close the parent window (the application itself)? Thanks.
3
by: T. Wintershoven | last post by:
Hi all, After a visitor has loged in, a session is started. The session is destroyed after the visitor clicked "Log out'. When the visitor forgets to log out and closes the browser...
6
by: phpmagesh | last post by:
Hi to all, I have a page which is to be automated, i explain you clearly: I have a page with 3 fields name mailid and message. what i can do with that page is i can type name mail id and...
0
gauchomatt
by: gauchomatt | last post by:
I have a liquid site which expands perfectly when the browser window is larger than the actual content. However, when I decrease the browser window size to a point that it's smaller horizontally than...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.