简体   繁体   English

禁用localStorage / sessionStorage时的jQuery回退

[英]jQuery fallback when localStorage/sessionStorage is disabled

I have a REST based service architecture. 我有一个基于REST的服务体系结构。 One service is used to login users. 一种服务用于登录用户。 A successful login request results in a auth_token sent back to the web client. 成功的登录请求导致auth_token发送回Web客户端。

I would like to store the token in localStorage which is working fine in most situations. 我想将令牌存储在localStorage ,在大多数情况下都可以正常工作。 However it is possible that the user disables localStorage or the browser is in private mode (as far as I know only an issue on Safari). 但是,用户可能会禁用localStorage或浏览器处于私有模式(据我所知,Safari上只有一个问题)。

My question is: Is there any concept I can use as a fallback when localStorage is not available? 我的问题是:当localStorage不可用时,有什么概念可以用作后备?

Is storing the token in the window variable an option? 将令牌存储在window变量中是否是一个选项?

Any ideas are appreciated. 任何想法表示赞赏。

Checkout this link to find whether you have local storage enabled or not. 查看此链接以查找是否启用了本地存储。

https://mathiasbynens.be/notes/localstorage-pattern https://mathiasbynens.be/notes/localstorage-pattern

Also, for the fallback you can use cookies always. 另外,对于后备,您可以始终使用cookies Or even if the cookies is not enabled, the only way to support is by URL param. 或即使未启用cookie,唯一支持的方法就是URL参数。 Usually, in these cases people will show a warning message staing their Localstorage/Cookie should be enabled in order to work with their site. 通常,在这些情况下,人们会显示警告消息,弄脏了应启用其Localstorage / Cookie的功能才能使用其站点。 Hope it helps . 希望能帮助到你 。

Alternatively, you can store in window.name which will be carried over on one browser tab; 或者,您可以将window.name存储在一个浏览器选项卡中; if you open the same page on anther tab it wont be available. 如果您在其他标签上打开同一页面,则该页面将不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM