Skip to content

Instantly share code, notes, and snippets.

@ovlb
Last active February 13, 2018 22:19
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 ovlb/e85a752f6e06261e493ef748bb91a234 to your computer and use it in GitHub Desktop.
Save ovlb/e85a752f6e06261e493ef748bb91a234 to your computer and use it in GitHub Desktop.
setCookie(status) {
if (status === 'opt-in' || status === 'opt-out') {
const secure = this.options.secure ? 'secure' : ''
const isNotHttps = location.protocol !== 'https:'
if (secure && isNotHttps) {
console.warn('Trying to set a secure cookie in an insecure context. This won’t work.')
}
document.cookie = `${this.options.cookieName}=${status}; expires=Fri, 30 Jan 2071 23:00:00 GMT; ${secure}; path=/`
} else {
console.error('Invalid state to set the status cookie. Use `opt-in` or `opt-out`.')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment