Hey Man,
Take a look at this article :
Save Changes on Close of Browser or When Exiting the Page[
^]
Anyway, you need to save the time in a cookie. Never use session for saving these types of data's because if you save these simple data's on your session, it means you are making a big memory usage(disk or even database) on your server. You ought to save time in user's cookie.Nevertheless This is not a very good option because user can delete his cookies. So, what is the real way ???
Solution : when user clicked on Start button, save his start time in the database or a file in the server and when he wants to close the page, you need to save the exit time too. If he wants to open the page, you should write a code on pageload event of your page that gets start time and exit time from server-side and gives it to a javascript timer countdown code to calculate the remaining time and back to the game again. This the way that you can see in countdown codes.