The simplest solution is, perhaps, simply marking the user as “active” every time he performs an action on your site (that is, every time a page is created on the server) - you already know how to do it.
And if the user has been marked as “active” for a long time (i.e. more than 5 minutes, for example, maybe more depending on the type of content that you have on your site), you might think that he is not more active - maybe not even on your site, actually.
Of course, you have a couple of minutes of delay before you discover the user is no more ...
- Ajax, : , , ...
, /, , ( , firefox, /!)