Skip to content

Instantly share code, notes, and snippets.

@deleteman
Created January 3, 2023 19:27
Show Gist options
  • Save deleteman/2a202ca9409d9c867f5c96c0811ea781 to your computer and use it in GitHub Desktop.
Save deleteman/2a202ca9409d9c867f5c96c0811ea781 to your computer and use it in GitHub Desktop.
function setCookie(name, value, days) {
let expires = "";
if (days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment