Whatever the name, cookies are small key-value pairs associated with an expiration date and with a domain/path, both of which are meant to ensure that the right cookies are read by the right servers. The information they contain is transmitted as part of the web-page request, and thus the data is available to the server and to the browser.
Cookies are accessible, like most other browser elements, through the document object. To create a cookie, you’ll need to provide a cookie name, or key, an associated value, a date when it expires, and a path associated with the cookie. To access it, you’ll access the document cookie and then have to parse the cookie out.
Luckily there’s a plethora of cookie functions out and about. To get a better idea of how they work, I’ll provide a variation of functions for setting, getting, and erasing a cookie and explain what happens with each step in the process.
To create a cookie, just assign the document cookie value a string with the following format:
cookieName=cookieValue; expirationdate; path
The cookie name and value are whatever you want and need, as long as the value is a simple value. I’ve used cookie names starting with ...