cookie name
cookie value
Optional
options: { Optional
domain?: stringA String indicating a valid domain where the cookie should be visible. The cookie will also be visible to all subdomains.
undefined Cookie is visible only to the domain or subdomain of the page where the cookie was created
Optional
expires?: numberExpire cookie after x days (negative to remove cookie)
undefined Cookie is removed when the user closes the browser
Optional
path?: stringA String indicating the path where the cookie is visible.
undefined
Optional
sameA String, allowing to control whether the browser is sending a cookie along with cross-site requests.
undefined No SameSite attribute set
Optional
secure?: booleanA Boolean indicating if the cookie transmission requires a secure protocol (https).
undefined No secure protocol requirement
// Create a cookie, valid across the entire site:
document.cookie = generateCookie('name', 'value')
// Create a cookie that expires 7 days from now, valid across the entire site:
document.cookie = generateCookie('name', 'value', { expires: 7 })
// Delete a cookie by setting the expires parameter to zero:
document.cookie = generateCookie('name', 'value', { expires: 0 })
Generates cookie string