Skip to content

Instantly share code, notes, and snippets.

@kevinSuttle
Created June 18, 2015 05:09
Show Gist options
  • Save kevinSuttle/8abdf8d35e20065616ac to your computer and use it in GitHub Desktop.
Save kevinSuttle/8abdf8d35e20065616ac to your computer and use it in GitHub Desktop.
Get cookie value with escaped quotes.
function getCookie(cookieName) {
if (!cookieName) { return null; }
return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")).replace(/['"]+/g, '') || null;
}
// Original function
// https://developer.mozilla.org/en-US/docs/Web/API/document/cookie#A_little_framework.3A_a_complete_cookies_reader.2Fwriter_with_full_unicode_support
@bgoonz
Copy link

bgoonz commented Nov 28, 2021

hi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment