This is in context to an ASP.Net application. The application makes use of a specific data which is set for a page. After this data has been set all the operations from this page onwards use the set data.
The problem is that if the user opens another tab with a competing data it overwrites the older data for the same session and for the same user which invalidates the operations on the first tab.
I know the suggested way is to refactor the code to remove such coupling but that is not possible. Here’s another thread that discussed this but didn’t specify any solutions other than refactoring the code (http://stackoverflow.com/questions/632062/ways-to-detect-ctrl-n-or-when-a-user-opens-a-new-window)
So, how can I detect (and notify the user) or stop the user from opening another tab – through javascript/Jquery?
You could set a session variable
isActiveand set it to true, along with all the other session data when the user opens the application the first time. After this, if the user opens another tab, check to see ifisActiveis true. If it is, inform the user and don’t set the data again.In pseudo-code, your logic should flow like this
This would be a better solution because there is no guarantee the user does not visit the page to set the session, then temporarily turn off Javascript to launch a new tab without you being notified.