Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tab specific cookies without using sessionStorage or any HTML5 features

I am interested in having users be able to login and logout with multiple user session cookies on my web app. Currently, authentication is done standard and a unique identifier allows me to authenticate a user when they visit our site back if they present an auth token that's available in their cookie. Typical use cases apply in that if the user logs out from one tab, it logs them out of another tab. Right now it requires having the user login from two unique browser instances in order to be able to login to two different accounts.

Is there a non-HTML5 way (using standard javascript cookies) to have tab-specific cookie identifiers? I'm assuming that there is no clear cut way of going about this and it would require some kind of hack + cooperation from the backend. If there is a solution that makes sense without using HTML5, that would be ideal.

like image 888
randombits Avatar asked Nov 25 '14 22:11

randombits


People also ask

Are cookies tab specific?

Cookies are specific to websites. If you have multiple tabs open to various pages on the same site they'll share cookies. Tabs open to different websites don't have access to cookies used by another site regardless of whether it's open in another tab. How do I set cookies in Chrome?

What is difference between sessionStorage and cookies?

Local storage and session storage both provide a large memory capacity. To be more specific, local Storage stores up to 10 megabytes and session storage stores up to 5 megabytes. On the other hand, cookies provide a very restrictive and small storage capacity of 4 kilobytes.

Do session cookies work across tabs?

If you open the same webpage in another tab in the same browser then the same cookies will be used for requests for that domain.

Are cookies stored in session storage?

Cookies and Sessions are used to store information. Cookies are only stored on the client-side machine, while sessions get stored on the client as well as the server. Read through this article to find out more about cookies and sessions and how they are different from each other.


1 Answers

You can't.

There are ways to deal with this condition, but none of them are simple.

If you want, you have to tell user to do like this: How to geek

From docs: Data stored using sessionStorage do not persist across browser tabs, even if two tabs both contain webpages from the same domain origin. In other words, data inside sessionStorage is confined to not just the domain and directory of the invoking page, but the browser tab in which the page is contained in. Contrast that to session cookies, which do persist data from tab to tab.

like image 69
Prateek Avatar answered Sep 20 '22 14:09

Prateek