In JavaScript, document.cookie property is used to create, read, change and delete cookies. There are 3 options while creating Javascript Cookies.
First thing is a name-value.
Syntax for name-value cookie is :
document.cookie=”username=Mike Hussey”;
Second thing is Expiration date, which allows a cookie to stay on the user’s computer. When a user closes the browser, cookies will be deleted automatically.
Syntax for adding the expiration date to a basic single cookie is :
document.cookie = “username=Mike Hussey; expires = Fri,14 Nov 2017 12:00:00 GMT”;
Third option is assigning a specific path name to a cookie. This is helpful when a page on the site to which the user returns is known.
Syntax for adding a pathname to a cookie is as follows:
document.cookie = “username=Mike Hussey; expires = Fri,14 Nov 2014 12:00:00 GMT; path=/”;
The document.cookie property will return cookies in a single string. For example,
cookie1 = value; cookie2 = value; and so on.