Skip to content

Instantly share code, notes, and snippets.

@ccarrasc
Last active December 18, 2015 16:49
Show Gist options
  • Save ccarrasc/5814237 to your computer and use it in GitHub Desktop.
Save ccarrasc/5814237 to your computer and use it in GitHub Desktop.
Get cookie value (must be same domain)
var getCookie = function (key) {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; ++i) {
var currentKey = cookies[i].substr(0, cookies[i].indexOf('='));
currentKey = currentKey.replace(/^\s+|\s+$/g, "");
if (currentKey === key) {
return cookies[i].substr(cookies[i].indexOf('=') + 1);
}
}
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment