当网页在不同浏览器中打开令牌没有得到保存在$ window.sessionStorage [英] Token not getting saved in $window.sessionStorage when page is opened in different browser

查看:205
本文介绍了当网页在不同浏览器中打开令牌没有得到保存在$ window.sessionStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在初始化时生成我登录到我的$ window.sessioStorage申请后的标记。

I'm initializing the token that is generated after I log in to my application in $window.sessioStorage .

var token = this.$window.sessionStorage["apiKey"];

不过,此令牌似乎是不确定的,当我复制URL(登录后),并重定向到登录页面不同browser.I'm打开。
的确$ window.sessionStorage持有变量的值在同一个浏览器窗口吗?或者这可能是另一种方式来留住令牌,即使我在不​​同的浏览器窗口中打开该页面的价值?

But this token seem to be undefined when I copy the url(after log in ) and open in different browser.I'm redirected back to the login page. Does $window.sessionStorage holds the values of variables in the same browser window?Or what could be another way to retain the value of token even if I opened the page in different browser window?

推荐答案

这是正确的行为。

在sessionStorage的属性,可以访问会话存储
  目的。的sessionStorage类似于本地存储,唯一的区别
  是同时存储在localStorage的数据没有过期设置,数据
  存储在sessionStorage的时候网页会话结束被清除。一个
  页会话持续,只要浏览器打开和生存
  在页面重新加载和恢复。打开网页在新标签或窗口
  将导致发起一个新的会话。

The sessionStorage property allows you to access a session Storage object. sessionStorage is similar to localStorage, the only difference is while data stored in localStorage has no expiration set, data stored in sessionStorage gets cleared when the page session ends. A page session lasts for as long as the browser is open and survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated.

您可以保留信息,即使关闭浏览器,并通过使用的localStorage 重新开放,其他时间,但是,正如我所说,如果你打开​​浏览器等,你必须设置项目agains。

You can keep information even if the browser is closed and reopend another time by using localStorage, but, as I said, if you open other browser you'll have to set items agains.

本地存储的例子这里

code例如:

// set something in localStorage
localStorage.setItem('bgcolor', 'green');


// get something from localStorage
localStorage.getItem('bgcolor') // it will output green

这篇关于当网页在不同浏览器中打开令牌没有得到保存在$ window.sessionStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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