The best way to do this is to set up a regular server polling to let him know that the user is still on the page. You can send an AJAX request once a minute to confirm that the user is still there, and log out from the server side if more time has passed since the last notification.
This may not be the most reliable solution, but it is very common and is likely to be effective for what you want to do.
source share