Skip to content

Instantly share code, notes, and snippets.

@andredelgado
Created October 14, 2014 15:55
Show Gist options
  • Save andredelgado/e745ae2fc597802f6313 to your computer and use it in GitHub Desktop.
Save andredelgado/e745ae2fc597802f6313 to your computer and use it in GitHub Desktop.
function setCookie(cookie_name, cookie_value, expire_days) {
var date = new Date();
date.setTime(date.getTime() + (expire_days*24*60*60*1000));
var expires = "expires="+date.toUTCString();
document.cookie = cookie_name + "=" + cookie_value + "; " + expires;
}
function getCookie(cookie_name) {
var name = cookie_name + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
}
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment