Create cookies from javascript

function SetCookie(cookieName,cookieValue,nDays,domain) {
  var today = new Date();
  var expire = new Date();
  if (nDays==null || nDays==0) nDays=1;
  expire.setTime(today.getTime() + 3600000*nDays);
  if(domain != ''){
        document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString()+";domain="+domain+";path=/";
    }else{
        document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
    }
}

Share and Enjoy

  • Facebook
  • Twitter
  • Google Plus
  • Live
  • Delicious
  • Digg
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
  • Instapaper
  • FriendFeed

Comments

  1. Thanks for any other great article. Where else may anybody get that kind of info in such a perfect way of writing? I have a presentation next week, and I am on the search for such information.