简体   繁体   中英

Using SessionStorage in javascript to store user context information

Can we use sessionStorage or localStorage of HTML5 to store the user context details to be shared across the different pages?

Consider a scenario, where i don't have server side storage access at first page, and the user context needs to be passed in later in a header,but before that in whi want to store the user name and his few other context details to be shared with other page. Is it recommended to use sessionStorage, cookies or is there any other alternative ?

I'd suggest the usage of JWT and yes, you can store it in the sessionStorage, but you have to be careful of the cross-site scripting attacks. You can take a further read here .

sessionStorage is in one tab in site.

sessionStorage.setItem('key', 'test');

go in this tab by site and get param

sessionStorage.getItem('key');

https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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