Cookie Attributes


In JavaScript Cookie Attributes, in order to enhance the functionality of the cookies, JavaScript provides some of the optional attributes.

expires:
Used to maintain the state of a cookie up to the specified date and time.

max-age:
Used to maintain the state of a cookie up to the specified time in seconds.

document.cookie = 'name=Jai; max-age=3600'

max-age:
Used to maintain the state of a cookie up to the specified time in seconds.

document.cookie = 'name=Jai; max-age=3600'

path:
Used to expand the scope of the cookie to all the pages of a website.

document.cookie = 'name=Jai; path="/testFolder"'

domain:
Used to specify the domain for which the cookie is valid.

document.cookie = 'name=Jai; domain="www.Pustudy.com";'

Example -

Example -