Oh, and also, the createGUID method is just a utility to make the session identifier unique. Obviously, you would change the "tab is good", "tab is bad" conditions to do whatever logic you want. Similar Anthony's answer, it sets an interval to make sure the originating tab keeps the entry fresh, so that if the browser crashes or somehow closes without calling the unload event (included in the comments but not part of the code for testing purposes), then there would just be a short delay before the application would run properly in a new browser window. I know this post is pretty old, but in case it helps anybody, I recently looked into basically doing the same thing using localStorage and sessionStorage. Way around ASP.NET session being shared across multiple tab windows.Use these instead if you went with server-side solution: even evercookies can be deleted so, give my first suggestion a go.Įvercookie is really doing a good job at storing most secure zombie cookies ever but since the library itself is a little bit heavy for browsers (storing a cookie takes more than 100ms each time) it's not really recommended for using in real-world web app. Side-note: Do know that every attempt in client side is not secure at all! client-side should help server-side, it shouldn't be used as the one and only source of security. Client-side: If you really need a strong check of this, use evercookie to store an already-logged-in cookie on client's machine.then on every other request, check for whether user with said credentials is already logged in or not. request them on their first visit of your site to enter with their credentials. Server-side (better): provide all your clients, a user name and password.If yes, generate a new pair for client if no, reject them. if it were missing, check with the server-side whether if the previous tab is closed or not (cleaned from database). On every browser's request, check window.name for the value. if server fails to receive the heartbeat, it cleans up database and de-register dead clients. Send a heartbeat every 1~2 seconds to your server containing both consistent ID and random one. Store the random one in window.name property which is tab-specific. You can generate consistent one from browser's user-agent or get it from server-side. One consistent one (this will be our SSID actually, since you limit tabs of a single browser, it's better to get generated form browser's unique parameters).It's the exact thing which is mentioned at this answer, You need 2 IDs: If (e.oldValue != e.newValue) tab_Warning() if tabGUID does not match then more than one tab and GUID Window.addEventListener("storage", storage_Handler, false) If (sessionStorage = null) sessionStorage = tab_GUID() get (set if not) tab GUID and store in tab session Here's the JS I have in master page, plus in the login page I have a localStorage.Clear to clear last tab from previous session. I haven't yet got to fixing it so the last tab used get's notification, work in progress. So if I have three tabs A,B,C then click something in tab C, tab A and B detect another tab is open and warn user of this. The listener then compares the tabs GUID to the one written to site storage and if they differ then it knows more than one tab is open. The using an event listener on the storage area I write the tab GUID to the sites localStorage area. The master page layout creates a tab GUID and stores it in sessionStorage area of the tab.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |