Jump to content

Set Field On Page Exit?


UberPooner

Recommended Posts

Hey guys, Im building a very basic/simple pjp ajax instant messaging board. you can see it here http://mistersaisho.com/intweb/final/member/page2.php login: hi pass: hi .I would like to add a section that would display current users on the page. I can add a mark in a field when user enters the page and load users with a mark. Though the problem im having is how to know when they leave the page if they just exit the browser.Is there a way i can call a function when a user exits the browser? what exactly happens to session variables when the browser is exited. your input would be greatly appreciated.

Link to comment
Share on other sites

You can detect when they leave the page, using the onunload event (onbeforeunload for Internet Explorer).However, it's preferrable to have a session that times out instead. Otherwise your system might leave a user connected if the onunload event failed (which is highly probable). All you need to do is, each time a request is sent to the server, compare the last time that each user sent a message with the current time, and if it is greater than five minutes, erase the user off the list.You can reduce the time. For example, instead of five minutes make it one.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...