Read a cookie value - Node.js Environment

Node.js examples for Environment:Cookie

Description

Read a cookie value

Demo Code

function CookieGet(name) {
  var ret = "";
  name += "=";
  var allCookies = document.cookie.split(';');
  var thisCookie;
  for(var i = 0; i < allCookies.length && ret == ""; i++) {
    thisCookie = allCookies[i].Trim();// w w  w. j  a  v a  2 s . c om
    if (thisCookie.indexOf(name) == 0) ret = thisCookie.substring(name.length).replace(/\[#\]/g, "\n");
  }
  return ret;
}

Related Tutorials