Skip to content

Instantly share code, notes, and snippets.

@xiaoliang2233
Created August 2, 2017 04:17
Show Gist options
  • Save xiaoliang2233/0b14ada9e5c06ffa0669496451adf318 to your computer and use it in GitHub Desktop.
Save xiaoliang2233/0b14ada9e5c06ffa0669496451adf318 to your computer and use it in GitHub Desktop.
getCookie
function getCookie(name) {
let cookies = document.cookie.split(';');
let cookiesObj = {};
cookies.forEach(c => {
if (!c) {
return;
}
let cs = c.trim().split('=');
if (cs.length < 2) {
return;
}
let key = cs[0];
let value = cs[1];
if (value == '""') {
value = "";
}
cookiesObj[key] = value;
});
return cookiesObj[name];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment