Bala
Bala

Reputation: 1148

Store data that persist across page using JavaScript or jQuery

I am working in SPA where I need to store user inputs in a variable and use the same in other pages . My Views are built in Javascript and controller in C#.

I found out Js-Cookie (https://github.com/js-cookie/js-cookie) . I was able to store data and use it across screens . This actually stores data in cookies so if the user diables the cookies in their browser then this does not work .

Is there any other way to store the data . Like in Asp.net application we have sessions . Is there any similar concepts like that ?

Appreciate your help .

Thanks,

Bk

Upvotes: 0

Views: 189

Answers (1)

mkelle
mkelle

Reputation: 224

you can use sessionStorage or localStorage

like so

(make data persist across session): sessionStorage.setItem('key1', 'val1'); //saves the value 'val1' under 'key1' sessionStorage.getItem('key1'); //returns the value related to 'key1', here 'val1'

(makes data persist across multiple sessions) localStorage.setItem('key1', 'val1'); localStorage.getItem('key1');

also try "superCookie" for a more sticky solution Hope it helps :)

Upvotes: 1

Related Questions