How to Track the Online Status of Users of my WebSite?

前端 未结 6 2011
星月不相逢
星月不相逢 2020-12-23 02:43

I want to track users that are online at the moment.

The definition of being online is when they are on the index page of the website which has the chat function.

6条回答
  •  星月不相逢
    2020-12-23 02:57

    I have not tried this, so take it with a grain of salt: Set an event handler for window.onunload that notifies the server when the user leaves the page. Some problems with this are 1.) the event won't fire if the browser or computer crashes, and 2.) if the user has two instances of the index page open and closes one, they will appear to logout unless you implement reference counting. On its own this is not robust, but combined with Jonathan's polling method, should allow you to have pretty good response time and larger intervals between updates.

提交回复
热议问题