Skip to content

Instantly share code, notes, and snippets.

@brandonros
Created February 21, 2019 06:04
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 brandonros/2868b6cd8b41a4170cfcdbb00f5879e6 to your computer and use it in GitHub Desktop.
Save brandonros/2868b6cd8b41a4170cfcdbb00f5879e6 to your computer and use it in GitHub Desktop.
Vanilla JavaScript frontend client cookie manipulation
const getCookie = (name) => {
var value = '; ' + document.cookie
var parts = value.split('; ' + name + '=')
if (parts.length === 2) {
return parts.pop().split(';').shift()
}
}
const setCookie = (name, value) => {
document.cookie = name + '=' + value + '; path=/'
}
const deleteCookie = (name) => {
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment