How to know if the user is still online on the website or offline?

前端 未结 1 1934
挽巷
挽巷 2021-01-15 01:58

I am building a chat system in an asp.net MVC website, if the user has no actions on the website for more than 2 minutes I will set his status to away.
My question is, h

相关标签:
1条回答
  • 2021-01-15 02:17

    To know if the user is on the site, you could send an AJAX request every minute from the client to the server and server-side check the time between the received requests to see if he is no longer on the page.

    If you want to the detect if the user is "AFK" but might still have the website opened on his browser, you'll have to add global events for key presses, mouse presses and mouse move, and only send the AJAX request each minute if there has been one of those event fired in the last minute.

    0 讨论(0)
提交回复
热议问题