Reputation: 5355
The application I am using is implementing some session timeout prompt using jquery. There is a timer that counts and if there is no user activity after predefined X minutes it shows user prompt
(Your session will end soon... Continue or Logout).
It uses the approach found here - http://www.codeproject.com/Articles/227382/Alert-Session-Time-out-in-ASP-Net.
However, this doesn't work if user opens new tab:
1) User logs in, timer starts counting user inactivity's.
2) User clicks some link that opens in new window (for example, in our case it is a long report running). Second tab is active, there is some response (crossbacks / postbacks that doesn't end session).
3) Second browser tab is active, there is some activity that doesn't end session.
4) However, first browser tab is inactive and counter is "thinking" that session should be closed, it displays appropriate message and then logout user.
This is not what we want. So the given approach is just some session timeout fix, but if user is active in another tab, then application will logout user anyway. That is not the desired thing. We have a Report Page. It functions so that it opens report in a new tab/window. And it could be run quite long. Report section take care of some callbacks, so session wont end in this tab. However, it would end in the second tab.
EDIT: I have the following sollution: "Store a Javascript cookie and check that to determine if the session has been extended in another tab?". I am still trying to understand this.
Upvotes: 1
Views: 960
Reputation: 17405
You can use the LocalStorage concept, to save the last activity time.
If you save it on one of the tabs, it will be accessible from the other tabs as well...
This is supported on all the modern browsers.
Example:
When activity is detected use:
localStorage['lastActivity'] = new Date();
When you want to check it:
var lastActityTime = localStorage['lastActivity'];
Upvotes: 2