I’m trying to figure out a way I can determine how long a user has been on a page. I’m open to javascript solutions that call some server script periodically, but I’m wondering if there are any better solutions than that?
I’ve read Can you fire an event in JavaScript before the user closes the window? and it seems useful, but I need to know for certain when the page is closed.
Is there any way I can determine if the page is “active”? (meaning on top of other tabs / windows and the user is paying attention to it? this is for an educational web application)
Ended up creating a javascript function which called a php script on the server periodically. Saved the ‘last-updated’ field in a database and set a minimum time before which it could be updated in order to ensure the polling function wasnt maliciously called by a user.