How to detect browser closing?

后端 未结 6 1580
故里飘歌
故里飘歌 2020-11-28 13:48

In my web app, when a user logs in, I add his Id to a vector of valid Ids in the servlet, when he logs out, I remove his Id from the vector, so I can see how many current us

6条回答
  •  孤独总比滥情好
    2020-11-28 14:23

    There is no foolproof way to do what you're trying to do, but both sblundy and Diodeus have plans that will cover most circumstances. There is nothing you can do about someone who turns off Javascript in their browser, or their internet connection goes down, or their power goes out. You should just cull sessions after a certain period of inactivity (which I think is what sblundy's suggestion of listening for session destruction will do).

提交回复
热议问题