document.cookie


Overview

document.cookie is a JavaScript property used to read and write cookies.

Read a cookie

JavaScript
alert(document.cookie)

This will display the cookies stored on this page. They always follow the following format: cookiename=cookievalue.

Writing a cookie

JavaScript
document.cookie = encodeURIComponent(cookie_name) + '=' + encodeURIComponent(cookie_value)

This will write a cookie, cookie_name is the cookie's name, and cookie_value the cookie's value.

See also

setrawcookie()
setcookie()
encodeURIComponent()
RFC 6265 (IETF)