While working with any language, We commonly need to share the data throughout the application. localStorage and sessionStorage is one of the most common ways to save user-related data at the browser which can be used throughout the application.
In this article, We will see how to use sessionStorage using Jquery. One other similar way to save data is localStorage. The sessionStorage object stores data only for a session. It means that the data stored in the sessionStorage will destroy when browser get closed but with localStorage data will not be deleted when browser gets closed. Click here to read more about the Difference between localStorage and sessionStorage
Load the main script jquery.session.js after loading the jQuery library.
<script src="/path/to/cdn/.../jquery.min.js"></script>
<script src="/path/to/...../jquery.session.js"></script>
The value will be added using “set”.
$.session.set(‘kae_name’, ‘key _value’);
Using “get” we can fetch specific session variable.
$.session.get(‘key_name’);
$.session.remove('key_name');
$.session.clear();
With the help of jQuery and session library above operations can be used. These are very easy and quick to implement at any kind of application.
Thanks for reading the article!