How can I detect in JavaScript if a session has terminated. I have a survey application that can take a while to complete. On the save button I want to see if the session is still active and if not to display a message. I don't want to go through messages indicating how much time before it closes.
Asked
Active
Viewed 530 times
0
-
when you say "session timed out," any sort of session is imposed by you, so it's really just a time-based decision on your part – Wold Jan 20 '17 at 20:51
-
2You could simply set a cookie when your session starts, valid for as long as a session lasts... Update it's expiry date as needed and on save, grab the cookie... If it's still there, session's still good. Otherwise, your session's expired. – nibnut Jan 20 '17 at 20:52
-
follow [this](http://stackoverflow.com/a/7029246) – Chandan Rai Jan 20 '17 at 20:54
-
Possible duplicate of [How to check whether session is null or not in javascript?](http://stackoverflow.com/questions/36347784/how-to-check-whether-session-is-null-or-not-in-javascript) – Heretic Monkey Jan 20 '17 at 20:56
-
1@MacPrawn that would work, provided that the cookie is not `httpOnly` (so it can be read through `document.cookie` with JS) – robertklep Jan 20 '17 at 20:56