Skip to content

Instantly share code, notes, and snippets.

@man-oi
Created May 14, 2019 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save man-oi/2043027827e7ee28c39128b7137e3d38 to your computer and use it in GitHub Desktop.
Save man-oi/2043027827e7ee28c39128b7137e3d38 to your computer and use it in GitHub Desktop.
function to get Cookie
export default function (cname) {
const name = `${cname}=`;
const decodedCookie = decodeURIComponent(document.cookie);
const ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i += 1) {
let c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment