Set a cookie value (path set to root) - Node.js File

Node.js examples for File:Path

Description

Set a cookie value (path set to root)

Demo Code

function CookieSet(name, value, minutes) {
  value = String(value).replace(/\r/g, "").replace(/\n/g, "[#]");
  if (minutes) {//from ww  w.j a v a2s . c o  m
    var date = new Date();
    date.setTime(date.getTime()+(minutes*60000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+String(value)+expires+"; path="+location.pathname.substr(0, location.pathname.indexOf("/",1)+1);
}

Related Tutorials