Skip to content

Instantly share code, notes, and snippets.

@DZuz14
Last active June 22, 2017 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DZuz14/b0153ab613a757db0d30ce9b84e2e601 to your computer and use it in GitHub Desktop.
Save DZuz14/b0153ab613a757db0d30ce9b84e2e601 to your computer and use it in GitHub Desktop.
Create Cookie With Javascript
function createCookie(name, value, expdays) {
var date, expires, serializedValue;
// Set Expiration date in the future
date = new Date();
date.setTime(date.getTime() + expdays * 86400000);
expires = 'expires=' + date.toUTCString();
// JSON stringify the object
serializedValue = JSON.stringify(value);
// Set The Cookie
document.cookie = name + '=' + serializedValue + ';' + expires + ';path=/';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment