{"id":223,"date":"2011-12-26T16:48:31","date_gmt":"2011-12-26T11:18:31","guid":{"rendered":"http:\/\/itechgenie.com\/myblog\/?p=223"},"modified":"2011-12-26T16:48:31","modified_gmt":"2011-12-26T11:18:31","slug":"simple-methods-to-create-read-and-delete-cookies-using-javascript","status":"publish","type":"post","link":"https:\/\/itechgenie.com\/myblog\/2011\/12\/simple-methods-to-create-read-and-delete-cookies-using-javascript\/","title":{"rendered":"Simple methods to Create, Read and Delete Cookies using JavaScript"},"content":{"rendered":"<p>Usage:<\/p>\n<p>1. createCookie(name,value,days) &#8211; Void function.<\/p>\n<blockquote><p>name &#8211; Name for the cookie to be created<br \/>\nvalue &#8211; Value of the cookie<br \/>\ndays(INT &#8211; Non Madatory) &#8211; Number of days to keep the cookie in browser. If not specified the cookie will expire as soon as soon the browser is closed.<\/p><\/blockquote>\n<p>2. readCookie(name) &#8211; Returns the value of the cookie.<\/p>\n<blockquote><p>name &#8211; Name given at the time of creation<\/p><\/blockquote>\n<p>3. eraseCookie(name) &#8211; Void function.<\/p>\n<blockquote><p>Dependency &#8211; createCookie method should be in place.<\/p><\/blockquote>\n<pre class=\"lang:js decode:true \">function createCookie(name,value,days) {\nif (days) {\nvar date = new Date();\ndate.setTime(date.getTime()+(days*24*60*60*1000));\nvar expires = \"; expires=\"+date.toGMTString();\n}\nelse var expires = \"\";\ndocument.cookie = name+\"=\"+value+expires+\"; path=\/\";\n}<\/pre>\n<pre class=\"lang:js decode:true \">\nfunction readCookie(name) {\nvar nameEQ = name + \"=\";\nvar ca = document.cookie.split(';');\nfor(var i=0;i &amp;lt; ca.length;i++) {\nvar c = ca[i];\nwhile (c.charAt(0)==' ') c = c.substring(1,c.length);\nif (c.indexOf(nameEQ) == 0)\nreturn c.substring(nameEQ.length,c.length);\n}\nreturn null;\n}\n<\/pre>\n<pre class=\"lang:js decode:true \">\nfunction eraseCookie(name) {\ncreateCookie(name,\"\",-1);\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Usage: 1. createCookie(name,value,days) &#8211; Void function. name &#8211; Name for the cookie to be created value &#8211; Value of the cookie days(INT &#8211; Non Madatory) &#8211; Number of days to keep the cookie in browser. If not specified the cookie will expire as soon as soon the browser is closed. 2. readCookie(name) &#8211; Returns the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/itechgenie.com\/myblog\/2011\/12\/simple-methods-to-create-read-and-delete-cookies-using-javascript\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Simple methods to Create, Read and Delete Cookies using JavaScript&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5,16,9],"tags":[23,85,53],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-how-to","category-javascript-2","category-snippets","tag-cookies","tag-javascript-2","tag-tips-tricks"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2HHtz-3B","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/itechgenie.com\/myblog\/wp-json\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itechgenie.com\/myblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itechgenie.com\/myblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itechgenie.com\/myblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itechgenie.com\/myblog\/wp-json\/wp\/v2\/comments?post=223"}],"version-history":[{"count":0,"href":"https:\/\/itechgenie.com\/myblog\/wp-json\/wp\/v2\/posts\/223\/revisions"}],"wp:attachment":[{"href":"https:\/\/itechgenie.com\/myblog\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itechgenie.com\/myblog\/wp-json\/wp\/v2\/categories?post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itechgenie.com\/myblog\/wp-json\/wp\/v2\/tags?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}