Skip to content

Instantly share code, notes, and snippets.

@ovlb

ovlb/FPD__setCookie.js

Last active Feb 13, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.