Amazon.ca Widgets

Very simple cookie reader

If you want to read cookies in javascript (browser) without any library, that’s the easiest function you can use:

var cookies = {};
document.cookie.split(";").forEach(c => {
	c = c.trim().split("=");
	cookies[c[0]] = c.length > 1 ? c[1] : "";
});
var userCookie = cookies.user;

That’s it !

Happy coding.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: