Skip to content

Instantly share code, notes, and snippets.

@seekshreyas
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save seekshreyas/c9f143f93ecf06fe7652 to your computer and use it in GitHub Desktop.

Select an option

Save seekshreyas/c9f143f93ecf06fe7652 to your computer and use it in GitHub Desktop.
Create a persistent cookie
var setCookie = function(name, val) {
//reference: http://stackoverflow.com/a/8733385/1887264
var expiration_date = new Date();
var cookie_string = '';
expiration_date.setFullYear(expiration_date.getFullYear() + 1);
// Build the set-cookie string:
cookie_string = name + '=' + val + '; path=/; expires=' + expiration_date.toGMTString();
// Create/update the cookie:
document.cookie = cookie_string;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment