{"id":1134,"date":"2012-10-18T13:28:14","date_gmt":"2012-10-18T13:28:14","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=1134"},"modified":"2012-10-18T13:34:29","modified_gmt":"2012-10-18T13:34:29","slug":"how-to-set-cookies-using-javascript","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/","title":{"rendered":"How to set cookies using JavaScript"},"content":{"rendered":"<p>Simple example to set\u00a0 the cookies using JavaScript<\/p>\n<pre class=\"brush:js\">jQuery.noConflict();\r\nvar wk_setcookies='yes';\t\r\n\r\nif(wk_setcookies=='yes'){\r\n\tjQuery('document').ready(function(){\r\n\t\tvar cook = readCookie('WebsiteTourSystem');\r\n\t\tif(cook!='true'){\r\n\t\t\tjQuery(window).load(function() {\r\n\t\t\t\tjQuery(this).joyride();\r\n\t\t\t});\r\n\t\t\tcreateCookie('WebsiteTourSystem', 'true',30);\r\n\t\t }\r\n\t});\r\n}\r\nelse{\r\n\tjQuery('document').ready(function(){\t\t\t\t\t\t\r\n\t\tjQuery(window).load(function() {\r\n\t\t\tjQuery(this).joyride();\r\n\t\t});\r\n\r\n\t });\r\n}\t\t\t\t  \r\n\r\nfunction readCookie(name){\r\n\tvar nameEQ=name+'=';\r\n\tvar ca=document.cookie.split(';');\r\n\tfor(var i=0;i&lt;ca.length;i++){\r\n\t\tvar c=ca[i];\r\n\t\twhile(c.charAt(0)==' ')\r\n\t\t\tc=c.substring(1,c.length);\r\n\t\tif(c.indexOf(nameEQ)==0)\r\n\t\treturn c.substring(nameEQ.length,c.length);\r\n\t} \r\n\treturn null;\r\n}\r\nfunction createCookie(name,value,days){\r\n\tif(days){\r\n\t\tvar date=new Date();\r\n\t\tdate.setTime(date.getTime()+(days*24*60*60*1000));\r\n\t\tvar expires=';expires='+date.toGMTString();\r\n\t} \r\n\telse\r\n\t\tvar expires='';\r\n\t\tdocument.cookie=name+'='+value+expires+'; path=\/';\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Simple example to set\u00a0 the cookies using JavaScript jQuery.noConflict(); var wk_setcookies=&#8217;yes&#8217;; if(wk_setcookies==&#8217;yes&#8217;){ jQuery(&#8216;document&#8217;).ready(function(){ var cook = readCookie(&#8216;WebsiteTourSystem&#8217;); if(cook!=&#8217;true&#8217;){ jQuery(window).load(function() { jQuery(this).joyride(); }); createCookie(&#8216;WebsiteTourSystem&#8217;, &#8216;true&#8217;,30); } }); } else{ jQuery(&#8216;document&#8217;).ready(function(){ jQuery(window).load(function() { jQuery(this).joyride(); }); }); } function readCookie(name){ var nameEQ=name+&#8217;=&#8217;; var ca=document.cookie.split(&#8216;;&#8217;); for(var i=0;i&lt;ca.length;i++){ var c=ca[i]; while(c.charAt(0)==&#8217; &#8216;) c=c.substring(1,c.length); if(c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length); } return null; } <a href=\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[198,79],"tags":[199,2064,200],"class_list":["post-1134","post","type-post","status-publish","format-standard","hentry","category-javascript","category-jquery","tag-cookies","tag-javascript","tag-set-cookie"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to set cookies using JavaScript - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to set cookies using JavaScript - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Simple example to set\u00a0 the cookies using JavaScript jQuery.noConflict(); var wk_setcookies=&#039;yes&#039;; if(wk_setcookies==&#039;yes&#039;){ jQuery(&#039;document&#039;).ready(function(){ var cook = readCookie(&#039;WebsiteTourSystem&#039;); if(cook!=&#039;true&#039;){ jQuery(window).load(function() { jQuery(this).joyride(); }); createCookie(&#039;WebsiteTourSystem&#039;, &#039;true&#039;,30); } }); } else{ jQuery(&#039;document&#039;).ready(function(){ jQuery(window).load(function() { jQuery(this).joyride(); }); }); } function readCookie(name){ var nameEQ=name+&#039;=&#039;; var ca=document.cookie.split(&#039;;&#039;); for(var i=0;i&lt;ca.length;i++){ var c=ca[i]; while(c.charAt(0)==&#039; &#039;) c=c.substring(1,c.length); if(c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length); } return null; } [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2012-10-18T13:28:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-18T13:34:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Sandeep\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sandeep\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/\"},\"author\":{\"name\":\"Sandeep\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/53c1b6c4937da7467b0493e192cba16e\"},\"headline\":\"How to set cookies using JavaScript\",\"datePublished\":\"2012-10-18T13:28:14+00:00\",\"dateModified\":\"2012-10-18T13:34:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/\"},\"wordCount\":15,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"cookies\",\"JavaScript\",\"set Cookie\"],\"articleSection\":[\"JavaScript\",\"jQuery\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/\",\"url\":\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/\",\"name\":\"How to set cookies using JavaScript - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2012-10-18T13:28:14+00:00\",\"dateModified\":\"2012-10-18T13:34:29+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to set cookies using JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/53c1b6c4937da7467b0493e192cba16e\",\"name\":\"Sandeep\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5beff2e054be0f90faa52b0b165374035b9d3f1ffa505dc3bfa0a1ac969bbbf2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5beff2e054be0f90faa52b0b165374035b9d3f1ffa505dc3bfa0a1ac969bbbf2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Sandeep\"},\"sameAs\":[\"http:\/\/webkul.com\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/sandeep\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to set cookies using JavaScript - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to set cookies using JavaScript - Webkul Blog","og_description":"Simple example to set\u00a0 the cookies using JavaScript jQuery.noConflict(); var wk_setcookies='yes'; if(wk_setcookies=='yes'){ jQuery('document').ready(function(){ var cook = readCookie('WebsiteTourSystem'); if(cook!='true'){ jQuery(window).load(function() { jQuery(this).joyride(); }); createCookie('WebsiteTourSystem', 'true',30); } }); } else{ jQuery('document').ready(function(){ jQuery(window).load(function() { jQuery(this).joyride(); }); }); } function readCookie(name){ var nameEQ=name+'='; var ca=document.cookie.split(';'); for(var i=0;i&lt;ca.length;i++){ var c=ca[i]; while(c.charAt(0)==' ') c=c.substring(1,c.length); if(c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length); } return null; } [...]","og_url":"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2012-10-18T13:28:14+00:00","article_modified_time":"2012-10-18T13:34:29+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Sandeep","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Sandeep","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/"},"author":{"name":"Sandeep","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/53c1b6c4937da7467b0493e192cba16e"},"headline":"How to set cookies using JavaScript","datePublished":"2012-10-18T13:28:14+00:00","dateModified":"2012-10-18T13:34:29+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/"},"wordCount":15,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["cookies","JavaScript","set Cookie"],"articleSection":["JavaScript","jQuery"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/","url":"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/","name":"How to set cookies using JavaScript - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2012-10-18T13:28:14+00:00","dateModified":"2012-10-18T13:34:29+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/how-to-set-cookies-using-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to set cookies using JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/53c1b6c4937da7467b0493e192cba16e","name":"Sandeep","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5beff2e054be0f90faa52b0b165374035b9d3f1ffa505dc3bfa0a1ac969bbbf2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5beff2e054be0f90faa52b0b165374035b9d3f1ffa505dc3bfa0a1ac969bbbf2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Sandeep"},"sameAs":["http:\/\/webkul.com"],"url":"https:\/\/webkul.com\/blog\/author\/sandeep\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/1134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=1134"}],"version-history":[{"count":7,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/1134\/revisions"}],"predecessor-version":[{"id":1136,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/1134\/revisions\/1136"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=1134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=1134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=1134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}