Skip to main content

addCookie

Adds a cookie.

See Set-Cookie at mdn for details about the parameters used.

addCookie(name, value, path, domain, expiry, isSecure, isHttpOnly)

Parameters#

  • name: Required. Cookie name as string.
  • value: Required. Cookie value as string.
  • path: Optional. Path where the cookie can be accessed as string. Defaults to /.
  • domain: Optional. Host name where cookie is accessible as string. Defaults to current url's host.
  • expiry: Optional. Milliseconds since current time when the cookie should expire. For example, to set a cookie for expiration in 365 days, provide 365 * 24 * 60 * 60 * 1000. If omitted, cookie deletes once browser is closed.
  • isSecure: Optional. Value indicating whether cookie is sent to server only in https connection as boolean. Defaults to false.
  • isHttpOnly: Optional. Value indicating whether js can access this cookie as boolean. Defaults to false.

Returns#

  • No value

Example#

# set a cookie for expiration in an houraddCookie('some-cookie', '1118;accepted', '/', 'example.com', 60*60*1000, true)