Skip to content

Instantly share code, notes, and snippets.

@Octagon-simon
Created October 16, 2021 13:52
Show Gist options
  • Select an option

  • Save Octagon-simon/28afe7f79f8160164d41207da745b1b1 to your computer and use it in GitHub Desktop.

Select an option

Save Octagon-simon/28afe7f79f8160164d41207da745b1b1 to your computer and use it in GitHub Desktop.
How to retrieve Cookie Values using JavaScript
//Use this function to retrieve cookies by their names
function getCookie(name) { 
 var re = new RegExp(name + "=([^;]+)"); 
 var value = re.exec(document.cookie); 
 return (value != null) ? unescape(value[1]) : null; 
}
//Call the function
getCookie('username');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment