Skip to content

Instantly share code, notes, and snippets.

@jonalvarezz
Created February 5, 2016 12:42
Show Gist options
  • Save jonalvarezz/ca531c3a8af83fb76fff to your computer and use it in GitHub Desktop.
Save jonalvarezz/ca531c3a8af83fb76fff to your computer and use it in GitHub Desktop.
Get cookies JavaScript
/*
* Get Cookie
* Return cookie value by key
*
* @author Mozilla Foundation
* @url https://developer.mozilla.org/en-US/docs/Web/API/document/cookie
*
* @param {string} Cookie's name to lookup
* @return {string} Cookie's value
*/
function getCookie (name) {
var cookieValue = null;
if (!name) { return null; }
return decodeURIComponent(
document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" +
encodeURIComponent(name).replace(/[\-\.\+\*]/g, "\\$&") +
"\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment