UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Javascript taking Value from cookie

code for how to read values from cookies in javascript

by Athil


Posted on 25 Jun 2017 Category: Javascript Views: 360

Edited on 25 Jun 2017


Here I am going to show how to read value to cookie in javascript

Demo

Reading value from Cookie

var CookieName = "cookiename=";
var DecodedCookie = decodeURIComponent(document.cookie);
var CookieArray = DecodedCookie.split(';');
for(var i = 0; i < CookieArray.length; i++)
{
   var c = CookieArray[i];
   while (c.charAt(0) == ' ')
   {
        c = c.substring(1);
  }
   if (c.indexOf(CookieName) == 0)
   {
        console.log(c.substring(CookieName.length, c.length));
   }

}


Leave a Comment:


Advertisement