JavaScript By Example

Cookies: 1. Write A Session Cookie

Web browsers distinguish between three different types of cookies. These types are session cookies, first party cookies, and third party cookies. You can create the first two of these types from your web page while the third party cookies are created by third party scripts attached to your page from other sites.

The difference between session cookies and first party cookies is where the cookie information is stored and how long it is kept for.

A session cookie is stored within the browser itself and is retained for as long as the browser remains open. Session cookies disappear as soon as the browser is closed.

A session cookie is the easiest one that you can create using JavaScript and is ideal for passing information between web pages during a single visit to your site by any visitor.

document.cookie = 'mycookie1='+cookievalue;
document.cookie = 'mycookie2='+anothervalue;