Link to home
Start Free TrialLog in
Avatar of ysgdel
ysgdel

asked on

How to read cookies in jquery

I need to read some cookies in a javascript objects using jquery. Any code sample is appreciated.
Avatar of leakim971
leakim971
Flag of Guadeloupe image

you've all here : https://github.com/carhartl/jquery-cookie
- plugin
- example
Avatar of aplusexpert
aplusexpert

You can read cookie this way

function readCookie(name) {
var nameEQ = escape(name) + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
}
return null;
}

Open in new window


Or you can also use JQuery cookie plugin.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Monica P
Monica P
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial