Skip to content

Instantly share code, notes, and snippets.

@Arieg419
Created September 17, 2017 19:21
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 Arieg419/f2eaecaa92398141da4095ff6cf2fba8 to your computer and use it in GitHub Desktop.
Save Arieg419/f2eaecaa92398141da4095ff6cf2fba8 to your computer and use it in GitHub Desktop.
fetch a cookie with a key of "username"
const fetchCookie = () => {
const name = "username" + "=";
const cookie_array = document.cookie.split(';');
for(let i = 0; i < cookie_array.length; i++) {
let c = cookie_array[i];
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