How can I list all cookies with JavaScript?
List all cookies with JavaScript
2686
19-Jul-2021
Updated on 19-Jul-2021
Anonymous User
04-Aug-2021Read a Cookie with JavaScript
With JavaScript, cookies can be read like this:
document.cookie will return all cookies in one string much like: cookie1=value; cookie2=value; cookie3=value;
You can list cookies for the current domain:
function listCookies() {var theCookies = document.cookie.split(';');
var aString = '';
for (var i = 1 ; i <= theCookies.length; i++) {
aString += i + ' ' + theCookies[i-1] + '\n';
}
return aString;
}
But you cannot list cookies for other domains for security reasons