使用特定于标签的Cookie而不使用sessionStorage或任何HTML5功能 [英] Tab specific cookies without using sessionStorage or any HTML5 features

查看:99
本文介绍了使用特定于标签的Cookie而不使用sessionStorage或任何HTML5功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感兴趣的是让用户能够在我的网络应用上登录并注销多个用户会话cookie。目前,身份验证是标准的,并且唯一标识符允许我在用户访问我们的站点时对其进行身份验证,如果他们提供了cookie中可用的身份验证令牌。典型用例适用于如果用户从一个选项卡注销,它会将其从另一个选项卡中注销。现在,它要求用户从两个独特的浏览器实例登录,以便能够登录到两个不同的帐户。

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.

是否有非HTML5方式(使用标准javascript cookie)具有特定于标签的cookie标识符?我假设没有明确的方法来解决这个问题,这需要从后端进行某种黑客+合作。如果有一个没有使用HTML5的解决方案,那将是理想的。

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.

推荐答案

你不能。

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

来自docs: 使用 sessionStorage 存储的数据不会在浏览器标签中保留,即使两个标签都包含来自同一域来源的网页。换句话说, sessionStorage 中的数据不仅限于调用页面的域和目录,还包含页面所在的浏览器选项卡。对比会话Cookie,它会将数据从标签页保留到标签页。

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.

这篇关于使用特定于标签的Cookie而不使用sessionStorage或任何HTML5功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆