<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Local Storage &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/tag/local-storage/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 11 Jul 2018 16:28:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>Local Storage &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Remove Filtered sessionStorage And localStorage</title>
		<link>https://www.sibeeshpassion.com/remove-filtered-sessionstorage-and-localstorage/</link>
					<comments>https://www.sibeeshpassion.com/remove-filtered-sessionstorage-and-localstorage/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 11 Aug 2015 00:32:47 +0000</pubDate>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Storage In HTML5]]></category>
		<category><![CDATA[Find Out Particular Local Storage And Delete]]></category>
		<category><![CDATA[Find Out Particular Session Storage And Delete]]></category>
		<category><![CDATA[Local Storage]]></category>
		<category><![CDATA[Remove Filtered sessionStorage And localStorage]]></category>
		<category><![CDATA[Remove Local Storage]]></category>
		<category><![CDATA[Remove session storage]]></category>
		<category><![CDATA[Session Storage]]></category>
		<category><![CDATA[Storage in HTML5]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=8541</guid>

					<description><![CDATA[[toc] Introduction In this post we well discuss how to remove all local storage and session storage or remove the storage according to the key values, for example, is a key contain a particular string, we will remove that local storage and session storage. We will find all the local storage and session storage first and then we will loop through each, if a user needs to delete a particular storage according to a particular condition, we will delete that storage alone. Both localStorage and sessionStorage has been introduced with HTML5. If you are new to storage mechanism in client [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h3>Introduction</h3>
<p>
In this post we well discuss how to remove all local storage and session storage or remove the storage according to the key values, for example, is a key contain a particular string, we will remove that local storage and session storage. We will find all the local storage and session storage first and then we will loop through each, if a user needs to delete a particular storage according to a particular condition, we will delete that storage alone. </p>
<p>Both <em>localStorage</em> and <em>sessionStorage </em>has been introduced with HTML5. If you are new to storage mechanism in client side, you can find out here: <a href="http://sibeeshpassion.com/tag/storage-in-html5/" target="_blank">Storage In HTML5</a>
</p>
<h3>Backgroud</h3>
<p>
I am working in a client-side application where we use <em>localStorage</em> and <em>sessionStorage </em> for saving some key informations. What I mean by key information is, like we store the mail id of the user who uses the application. There I got a requirement of deleting the <em>localStorage</em> and <em>sessionStorage </em> according to the key value. For example, I needed to delete the storage values whose keys start with &#8220;logged&#8221;. I did the requirement and thought to share with you all. I hope someone will find it is useful.
</p>
<h3>Using the code</h3>
<p>
To start with you need to include jquery reference.</p>
<p>[js]<br />
 &lt;script src=&quot;https://code.jquery.com/jquery-2.1.4.min.js&quot;&gt;&lt;/script&gt;<br />
[/js]</p>
<p>Now we need to set the <em>localStorage</em> and <em>sessionStorage </em> right? </p>
<p>Add the storage values in the ready event.</p>
<p>[js]<br />
localStorage.setItem(&quot;First1&quot;,&quot;First Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;First1&quot;,&quot;First Session Storage&quot;);<br />
			localStorage.setItem(&quot;Second1&quot;,&quot;Second Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;Second1&quot;,&quot;Second Session Storage&quot;);<br />
[/js]</p>
<p>So we have set our <em>localStorage</em> and <em>sessionStorage </em>. Now we need to check whether it is saved or not right? Just run your page and see your browser console.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1.png"><img fetchpriority="high" decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1-1024x256.png" alt="Remove_Filtered_sessionStorage_And_localStorage1" width="634" height="159" class="alignnone size-large wp-image-8551" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1-1024x256.png 1024w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1-300x75.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1-768x192.png 768w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1-400x100.png 400w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1.png 634w" sizes="(max-width: 634px) 100vw, 634px" /></a></p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage2-e1438859495855.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage2-e1438859495855.png" alt="Remove_Filtered_sessionStorage_And_localStorage2" width="650" height="177" class="alignnone size-full wp-image-8561" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage2-e1438859495855.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage2-e1438859495855-300x82.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage2-e1438859495855-400x109.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Now we will add some elements where we can fire the delete events. Cool?</p>
<p>[html]<br />
 &lt;a href=&quot;#&quot; id=&quot;removeAllLocalStorage&quot;&gt;Click To Remove All Local Storage&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllLocalStorageWhichStarts&quot;&gt;Click To Remove All Local Storage Which Starts With &quot;First&quot;&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllSessionStorage&quot;&gt;Click To Remove All Session Storage&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllSessionStorageWhichStarts&quot;&gt;Click To Remove All Session Storage Which Starts With &quot;First&quot;&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
[/html]</p>
<p>Once that is done, we add the click event scripts.</p>
<p>[js]<br />
 &lt;script&gt;<br />
       $(document).ready(function(){<br />
			localStorage.setItem(&quot;First1&quot;,&quot;First Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;First1&quot;,&quot;First Session Storage&quot;);<br />
			localStorage.setItem(&quot;Second1&quot;,&quot;Second Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;Second1&quot;,&quot;Second Session Storage&quot;);</p>
<p>            $(&quot;#removeAllLocalStorage&quot;).click(function(){<br />
				Object.keys(localStorage)<br />
				.forEach(function (key) {<br />
						localStorage.removeItem(key);<br />
				});<br />
            });<br />
			$(&quot;#removeAllLocalStorageWhichStarts&quot;).click(function(){<br />
				Object.keys(localStorage)<br />
				.forEach(function (key) {<br />
						if ((/^First/.test(key))) {<br />
							localStorage.removeItem(key);<br />
						}<br />
				});<br />
            });<br />
			$(&quot;#removeAllSessionStorage&quot;).click(function(){<br />
				Object.keys(sessionStorage)<br />
				.forEach(function (key) {<br />
						sessionStorage.removeItem(key);<br />
				});<br />
            });<br />
			$(&quot;#removeAllSessionStorageWhichStarts&quot;).click(function(){<br />
				Object.keys(sessionStorage)<br />
				.forEach(function (key) {<br />
						if ((/^First/.test(key))) {<br />
							sessionStorage.removeItem(key);<br />
						}<br />
				});<br />
            });<br />
       });<br />
      &lt;/script&gt;<br />
[/js]	 </p>
<p>So everything is set. Now the only pending thing is just run and see the output. </p>
<p>First, we will fire the click event which removes all the local storage. ok? </p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage3-e1438859851133.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage3-e1438859851133.png" alt="Remove_Filtered_sessionStorage_And_localStorage3" width="650" height="266" class="alignnone size-full wp-image-8581" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage3-e1438859851133.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage3-e1438859851133-300x123.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage3-e1438859851133-400x164.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Once you clicked, you can see all of your local storage items have been removed.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage4-e1438859935922.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage4-e1438859935922.png" alt="Remove_Filtered_sessionStorage_And_localStorage4" width="650" height="102" class="alignnone size-full wp-image-8591" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage4-e1438859935922.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage4-e1438859935922-300x47.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage4-e1438859935922-400x63.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Now we will reload the page and set the storage items again, this time we will fire the event which delete the local storage value which has key starts with &#8220;First&#8221;.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage5-e1438860090376.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage5-e1438860090376.png" alt="Remove_Filtered_sessionStorage_And_localStorage5" width="650" height="264" class="alignnone size-full wp-image-8601" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage5-e1438860090376.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage5-e1438860090376-300x122.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage5-e1438860090376-400x162.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Once you clicked you can see only the storage element which has key starts with &#8220;First&#8221; has been removed.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage6-e1438860182653.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage6-e1438860182653.png" alt="Remove_Filtered_sessionStorage_And_localStorage6" width="650" height="101" class="alignnone size-full wp-image-8611" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage6-e1438860182653.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage6-e1438860182653-300x47.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage6-e1438860182653-400x62.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Next, we will fire the click event which removes all the session storage. ok? </p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage7-e1438860272461.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage7-e1438860272461.png" alt="Remove_Filtered_sessionStorage_And_localStorage7" width="650" height="285" class="alignnone size-full wp-image-8621" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage7-e1438860272461.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage7-e1438860272461-300x132.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage7-e1438860272461-400x175.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Once you clicked, you can see all of your session storage items have been removed.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage8-e1438860363488.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage8-e1438860363488.png" alt="Remove_Filtered_sessionStorage_And_localStorage8" width="650" height="121" class="alignnone size-full wp-image-8631" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage8-e1438860363488.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage8-e1438860363488-300x56.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage8-e1438860363488-400x74.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Now we will reload the page and set the storage items again, this time we will fire the event which deletes the session storage value which has key starts with &#8220;First&#8221;.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage9-e1438860452170.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage9-e1438860452170.png" alt="Remove_Filtered_sessionStorage_And_localStorage9" width="650" height="280" class="alignnone size-full wp-image-8641" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage9-e1438860452170.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage9-e1438860452170-300x129.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage9-e1438860452170-400x172.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Once you clicked you can see only the session storage element which has key starts with &#8220;First&#8221; has been removed.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage10-e1438860535759.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage10-e1438860535759.png" alt="Remove_Filtered_sessionStorage_And_localStorage10" width="650" height="126" class="alignnone size-full wp-image-8651" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage10-e1438860535759.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage10-e1438860535759-300x58.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage10-e1438860535759-400x78.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>So we have done everything.
</p>
<h3>Complete Code</h3>
<p>
[html]<br />
&lt;html&gt;<br />
   &lt;head&gt;<br />
      &lt;title&gt;Remove all session storage,local storage or remove by key which starts with a particular string &#8211; Sibeesh Passion&lt;/title&gt;<br />
      &lt;script src=&quot;https://code.jquery.com/jquery-2.1.4.min.js&quot;&gt;&lt;/script&gt;<br />
   &lt;/head&gt;<br />
   &lt;body&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllLocalStorage&quot;&gt;Click To Remove All Local Storage&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllLocalStorageWhichStarts&quot;&gt;Click To Remove All Local Storage Which Starts With &quot;First&quot;&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllSessionStorage&quot;&gt;Click To Remove All Session Storage&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllSessionStorageWhichStarts&quot;&gt;Click To Remove All Session Storage Which Starts With &quot;First&quot;&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;div id=&quot;body&quot;&gt;&lt;/div&gt;<br />
      &lt;script&gt;<br />
       $(document).ready(function(){<br />
			localStorage.setItem(&quot;First1&quot;,&quot;First Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;First1&quot;,&quot;First Session Storage&quot;);<br />
			localStorage.setItem(&quot;Second1&quot;,&quot;Second Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;Second1&quot;,&quot;Second Session Storage&quot;);</p>
<p>            $(&quot;#removeAllLocalStorage&quot;).click(function(){<br />
				Object.keys(localStorage)<br />
				.forEach(function (key) {<br />
						localStorage.removeItem(key);<br />
				});<br />
            });<br />
			$(&quot;#removeAllLocalStorageWhichStarts&quot;).click(function(){<br />
				Object.keys(localStorage)<br />
				.forEach(function (key) {<br />
						if ((/^First/.test(key))) {<br />
							localStorage.removeItem(key);<br />
						}<br />
				});<br />
            });<br />
			$(&quot;#removeAllSessionStorage&quot;).click(function(){<br />
				Object.keys(sessionStorage)<br />
				.forEach(function (key) {<br />
						sessionStorage.removeItem(key);<br />
				});<br />
            });<br />
			$(&quot;#removeAllSessionStorageWhichStarts&quot;).click(function(){<br />
				Object.keys(sessionStorage)<br />
				.forEach(function (key) {<br />
						if ((/^First/.test(key))) {<br />
							sessionStorage.removeItem(key);<br />
						}<br />
				});<br />
            });<br />
       });<br />
      &lt;/script&gt;</p>
<p>   &lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]
</p>
<h3>Conclusion</h3>
<p>
Thanks a lot for reading. Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.
</p>
<h3>Your turn. What do you think?</h3>
<p>
A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.
</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/remove-filtered-sessionstorage-and-localstorage/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Working With Client Side Local Storage</title>
		<link>https://www.sibeeshpassion.com/working-with-client-side-local-storage/</link>
					<comments>https://www.sibeeshpassion.com/working-with-client-side-local-storage/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 03 Aug 2015 00:09:38 +0000</pubDate>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Local Storage]]></category>
		<category><![CDATA[Storage in HTML5]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=1411</guid>

					<description><![CDATA[[toc] Introduction In this article, we will learn how to use local storage in HTML5. For many years, we developers were depending on the server only for saving the data. And we used to retrieve the data by sending a request to our server and by manipulating some queries we could manage the formation, updating, insertion and so on. Great, we were doing a fantastic job. But as the day’s passes, we must move on to the next level. Nowadays all are busy in their life, so a person can wait a maximum of a few seconds for a request [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h3>Introduction</h3>
<p>
In this article, we will learn how to use local storage in HTML5. For many years, we developers were depending on the server only for saving the data. And we used to retrieve the data by sending a request to our server and by manipulating some queries we could manage the formation, updating, insertion and so on. Great, we were doing a fantastic job.</p>
<p>But as the day’s passes, we must move on to the next level. Nowadays all are busy in their life, so a person can wait a maximum of a few seconds for a request that he has given in your blog, or website, or in your product. If it takes much time, he/she will just close the window and start searching for an alternative. Am I right?</p>
<p>Yeah, it happens when you are depending completely on the server. For each query, it will take some seconds. Just because of this, we started using the client-side state management techniques, mostly cookies.</p>
<p>But we do have the following issues if we are using cookies also:</p>
<p>The cookies can have only a limited amount of data, which is definitely not enough for us to work on (4096 bytes).<br />
And as the number of requests increases, the data amount in cookies also increase. So at a point in time, we may encounter some performance issues. So in the modern web, we have a new solution, Local Storage.
</p>
<h3>Source Code</h3>
<p>Download the source code here: <a href="https://code.msdn.microsoft.com/Client-Side-Local-Storage-1db5f707" target="_blank">Local Storage </a></p>
<h3>Background</h3>
<p>Currently, I am working on a dashboard application. As you all know a dashboard application must be as fast as possible. It must not make a user wait. So most of our codes are on the client side. So we are storing the necessary data on the client side itself, that makes my app fast. And we are using jQuery.</p>
<h3>Using the code</h3>
<p>Now we will work on how to save the data in local storage and retrieve it when we need it.</p>
<h4>Saving the Data</h4>
<p>To save the data we do have a function called <em>setItem().</em> We can use the following syntax.</p>
<p>[js]<br />
localStorage.setItem(“item”, “http://sibeeshpassion.com/”)<br />
[/js]</p>
<p>Before going for this, you must check that your browser supports this feature since this is only applicable to modern browsers.</p>
<h4>To check whether it supports it or not:</h4>
<p>[js]<br />
if (localStorage) {<br />
}<br />
else {<br />
$(“#showitem”).text(“your browser does not support this feature”);<br />
}<br />
[/js]</p>
<h4>Retrieving the data from local storage</h4>
<p>We can use the <em>getItem() </em>function to retrieve the data from the local storage.</p>
<p>Please see the following syntax.<br />
[js]<br />
var itm = localStorage.getItem(“item”);<br />
[/js]</p>
<p>Great, you have it. Congratulations.</p>
<p>Now we will work on how to remove this item from local storage.</p>
<h4>Removing data from the local storage</h4>
<p>To remove the data form the local storage, please see the following syntax.<br />
[js]<br />
localStorage.removeItem(“item”);<br />
[/js]</p>
<h4>Removing the all data from localStorage</h4>
<p>To remove the data form the localStorage, please see the following syntax.<br />
[js]<br />
localStorage.clear();<br />
[/js]</p>
<h3>Demo</h3>
<p>Here we will create 3 buttons and one h2 tag as in the following markup.</p>
<p>[html]<br />
&lt;input type=“submit” id=“setitem” value=“set Item” /&gt;<br />
&lt;input type=“submit” id=“getitem” value=“get Item” /&gt;<br />
&lt;input type=“submit” id=“removeitem” value=“remove Item” /&gt;<br />
&lt;h2 id=“showitem”&gt;&lt;/h2&gt;<br />
[/html]</p>
<p>Now we will add the jQuery reference.</p>
<p>[js]<br />
&lt;script src=“jquery-1.11.1.min.js”&gt;&lt;/script&gt;<br />
[/js]</p>
<h4>Set the Item</h4>
<p>[js]<br />
$(“#setitem”).click(function () {<br />
localStorage.setItem(“item”, “http://sibeeshpassion.com/”)<br />
});<br />
[/js]</p>
<p>Once you set the item to localStorage, you can see it in your browser. To see it, press F12 after pressing the set Item button, then go to the resources tab.</p>
<p>Figure: Prior to setting the item</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/03/set_items_to_local_storage.jpg"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/03/set_items_to_local_storage.jpg" alt="set_items_to_local_storage" width="611" height="265" class="alignnone size-full wp-image-8501" srcset="/wp-content/uploads/2015/03/set_items_to_local_storage.jpg 611w, /wp-content/uploads/2015/03/set_items_to_local_storage-300x130.jpg 300w, /wp-content/uploads/2015/03/set_items_to_local_storage-400x173.jpg 400w" sizes="(max-width: 611px) 100vw, 611px" /></a></p>
<p>Figure: After setting the item</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/03/set_items_to_local_storage1.jpg"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/03/set_items_to_local_storage1.jpg" alt="set_items_to_local_storage1" width="692" height="297" class="alignnone size-full wp-image-8511" srcset="/wp-content/uploads/2015/03/set_items_to_local_storage1.jpg 634w, /wp-content/uploads/2015/03/set_items_to_local_storage1-300x129.jpg 300w, /wp-content/uploads/2015/03/set_items_to_local_storage1-400x172.jpg 400w" sizes="(max-width: 692px) 100vw, 692px" /></a></p>
<h4>Get the Item</h4>
<p>[js]<br />
$(“#getitem”).click(function () {<br />
                    var itm = localStorage.getItem(“item”)<br />
                    $(“#showitem”).text(itm);<br />
                });<br />
[/js]</p>
<h4>Remove the Item</h4>
<p>[js]<br />
$(“#removeitem”).click(function () {<br />
                    localStorage.removeItem(“item”);<br />
                    $(“#showitem”).text(”);<br />
                });<br />
[/js]</p>
<h3>Complete Code</h3>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html xmlns=“http://www.w3.org/1999/xhtml”&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Use Of Local Storage – Sibeesh|Passion&lt;/title&gt;<br />
    &lt;script src=“jquery-1.11.1.min.js”&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        $(function () {<br />
            if (localStorage) {<br />
                $(“#setitem”).click(function () {<br />
                    localStorage.setItem(“item”, “http://sibeeshpassion.com/”)<br />
                });<br />
                $(“#getitem”).click(function () {<br />
                    var itm = localStorage.getItem(“item”)<br />
                    $(“#showitem”).text(itm);<br />
                });<br />
                $(“#removeitem”).click(function () {<br />
                    localStorage.removeItem(“item”);<br />
                    $(“#showitem”).text(”);<br />
                });<br />
            }<br />
            else {<br />
                $(“#showitem”).text(“your browser does not support this feature”);<br />
            }<br />
        });<br />
&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;input type=“submit” id=“setitem” value=“set Item” /&gt;<br />
    &lt;input type=“submit” id=“getitem” value=“get Item” /&gt;<br />
    &lt;input type=“submit” id=“removeitem” value=“remove Item” /&gt;<br />
    &lt;h2 id=“showitem”&gt;&lt;/h2&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<h3>Conclusion</h3>
<p>Thanks a lot for reading. Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h3>Your turn. What do you think?</h3>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/working-with-client-side-local-storage/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Basic Difference Between Local Storage and Session Storage in HTML 5</title>
		<link>https://www.sibeeshpassion.com/basic-difference-between-local-storage-and-session-storage-in-html-5/</link>
					<comments>https://www.sibeeshpassion.com/basic-difference-between-local-storage-and-session-storage-in-html-5/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sun, 29 Mar 2015 20:14:03 +0000</pubDate>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Difference between local storage and session storage]]></category>
		<category><![CDATA[Local Storage]]></category>
		<category><![CDATA[Session Storage]]></category>
		<category><![CDATA[Storage in HTML5]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=1501</guid>

					<description><![CDATA[[toc] Introduction This article explains what is the basic difference between HTML 5 local storage and session storage. Basically, both session storage and local storage are part of storage mechanism which is introduced with HTML5. By using these two, we can store information on client side itself. I hope you will like it. If you are new to the term local storage, I recommend you to read my article here: Local Storage Basic scenario where you can use If you need to carry a value throughout your application or throughout your pages, you can use local storage. For example, we [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h3>Introduction</h3>
<p>
This article explains what is the basic difference between HTML 5 local storage and session storage. Basically, both session storage and local storage are part of storage mechanism which is introduced with HTML5. By using these two, we can store information on client side itself.  I hope you will like it.</p>
<p>If you are new to the term local storage, I recommend you to read my article here: <a href="http://sibeeshpassion.com/working-with-client-side-local-storage/" target="_blank">Local Storage</a></p>
<p><h3>Basic scenario where you can use</h3>
<p>
If you need to carry a value throughout your application or throughout your pages, you can use local storage. For example, we can store a logged-in username in local storage that we may need to access all the pages. I strongly recommend to not store any secured data (for example a “password”) in local storage.</p>
<p>In some scenario, we may need to set a key element depending on the pages we have in the application. For example, if we need to store the page name (any key element that may be different).<br />
So let’s start</p>
<p><h3>Using the code</h3>
<p>
Here in my application, I have added two HTML5 pages.</p>
<p><em>HtmlPage1.html</em><br />
<em>HtmlPage2.html</em></p>
<p>In <em>HtmlPage1.html</em> I have set local storage and session storage, now I am trying to access that in <em>HtmlPage2.html</em>. Please see the following source.</p>
<p><em>HtmlPage1.html</em><br />
[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html<br />
    xmlns=“http://www.w3.org/1999/xhtml”&gt;<br />
    &lt;head&gt;<br />
        &lt;title&gt;Difference between local storage and session storage&lt;/title&gt;<br />
        &lt;script&gt;<br />
            localStorage.setItem(“myKey”, 1);<br />
            sessionStorage.setItem(“myKey”, 1);<br />
            var myVal = localStorage.getItem(“myKey”);<br />
            alert(“My local storage value is : ” + myVal);<br />
            alert(“My session storage value is : ” + sessionStorage.getItem(“myKey”));<br />
        &lt;/script&gt;<br />
    &lt;/head&gt;<br />
    &lt;body&gt;<br />
    &lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p><em>HtmlPage2.html</em><br />
[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html<br />
    xmlns=“http://www.w3.org/1999/xhtml”&gt;<br />
    &lt;head&gt;<br />
        &lt;title&gt;Difference between local storage and session storage&lt;/title&gt;<br />
        &lt;script&gt;<br />
            var myVal = localStorage.getItem(“myKey”);<br />
            alert(“My local storage value is : ” + myVal);<br />
            alert(“My session storage value is : ” + sessionStorage.getItem(“myKey”));<br />
        &lt;/script&gt;<br />
    &lt;/head&gt;<br />
    &lt;body&gt;<br />
    &lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p>When you run the first page, in the browser console you will see as in the following image.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/03/local-storage.jpg"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/03/local-storage.jpg" alt="local storage" width="624" height="135" class="alignnone size-full wp-image-8461" srcset="/wp-content/uploads/2015/03/local-storage.jpg 624w, /wp-content/uploads/2015/03/local-storage-300x65.jpg 300w, /wp-content/uploads/2015/03/local-storage-620x135.jpg 620w, /wp-content/uploads/2015/03/local-storage-400x87.jpg 400w" sizes="(max-width: 624px) 100vw, 624px" /></a></p>
<p>Figure: Local Storage</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/03/session-storage.jpg"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/03/session-storage.jpg" alt="session storage" width="624" height="135" class="alignnone size-full wp-image-8462" srcset="/wp-content/uploads/2015/03/session-storage.jpg 624w, /wp-content/uploads/2015/03/session-storage-300x65.jpg 300w, /wp-content/uploads/2015/03/session-storage-620x135.jpg 620w, /wp-content/uploads/2015/03/session-storage-400x87.jpg 400w" sizes="(max-width: 624px) 100vw, 624px" /></a></p>
<p>Figure: Session Storage</p>
<p>Now it is time to run the second page. Once you run that please check in the console. You can see as follows.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/03/htmlpage2-local-storage.jpg"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/03/htmlpage2-local-storage.jpg" alt="htmlpage2 local storage" width="624" height="301" class="alignnone size-full wp-image-8471" srcset="/wp-content/uploads/2015/03/htmlpage2-local-storage.jpg 624w, /wp-content/uploads/2015/03/htmlpage2-local-storage-300x145.jpg 300w, /wp-content/uploads/2015/03/htmlpage2-local-storage-400x193.jpg 400w" sizes="(max-width: 624px) 100vw, 624px" /></a></p>
<p>Figure: Local storage</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/03/htmlpage2-session-storage.jpg"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/03/htmlpage2-session-storage.jpg" alt="htmlpage2 session storage" width="624" height="307" class="alignnone size-full wp-image-8481" srcset="/wp-content/uploads/2015/03/htmlpage2-session-storage.jpg 624w, /wp-content/uploads/2015/03/htmlpage2-session-storage-300x148.jpg 300w, /wp-content/uploads/2015/03/htmlpage2-session-storage-400x197.jpg 400w" sizes="(max-width: 624px) 100vw, 624px" /></a></p>
<p>Figure: Session storage</p>
<p>Please note that session storage is null. You can see the session storage only if you set it on that running page.
</p>
<h3>Conclusion</h3>
<p>
Thanks a lot for reading. Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.
</p>
<h3>Your turn. What do you think?</h3>
<p>
A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.
</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/basic-difference-between-local-storage-and-session-storage-in-html-5/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
