I have set a cookie using
document.cookie =
\'MYBIGCOOKIE=\' + value +
\'; expires=\' + now.toGMTString() +
\'; path=/\';
No
The simplest way to read a cookie I can think is using Regexp like this:
**Replace COOKIE_NAME
with the name of your cookie.
document.cookie.match(/COOKIE_NAME=([^;]*);/)[1]
How does it work?
Cookies are stored in document.cookie
like this: cookieName=cookieValue;cookieName2=cookieValue2;.....
The regex searches the whole cookie string for literaly "COOKIE_NAME="
and captures anything after it that is not a semicolon until it actually finds a semicolon;
Then we use [1]
to get the second item from array, which is the captured group.