0

I have understood that this is the most effective way to go about this but honestly I don't really understand it.

I have made a chat/ messaging system that stores every message in a database table and displays them on the page ordered by when they were sent.

Now I want to be able to determine if the user has read the message or not. That's why I want to know when the user last left the chat page, so that I can compare that time and date to the time and date stored in the database.

I found a thread where someone wanted to know the time the user spent on a page by i only want to know when the user left.

If you've got a better way to go about this I'm open for suggestions.

1 Answers1

0
window.onbeforeunload = function(){
   if(unreadMessages.length > 0){
       return 'You have new message. Really want to leave?';  // confirms quit or page refresh
   }else{
       return null;  // lets user go
   }
};
gorpacrate
  • 5,109
  • 3
  • 21
  • 18