Create, Read, and Detele Cookies in Javascript


Thursday, September 22, 2011

Hello Friends,

This post will explain you how you can create, read and delete the cookies in your webpage using Javascript.

Here is the code to create cookies,
In this below code, you can see, Cookies is Set to Name "RajeshCookie" and value is set to "Rajesh" and
its expire time is set to next month as shown in below code.


//for creating a cookie
<script type="text/javascript">
<!--
   var today = new Date();
   var nextMonth = new Date(today.getYear(), today.getMonth()+1, today.getDate());
   setCookie("RajeshCookie", "Rajesh", nextMonth);
// -->
</script>


Here is the code to read cookies,


//for reading the cookie
<script type="text/javascript">
<!--
      var szName = getCookie("RajeshCookie");
// -->
</script>


Here is the code to Delete cookies,


//for deleting the cookie
<script type="text/javascript">
<!--
      deleteCookie('RajeshCookie');
// -->
</script>


Let me know, if you have any query..




Thanks Hope this post will help you, if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer
e-Procurement Technologies Ltd (India)
www.abcprocure.com 
 
 


No comments :