Skip to content

Instantly share code, notes, and snippets.

@DZuz14
Created June 22, 2017 12: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 DZuz14/05e7fae272e0bf1b58f12cb4acc0924b to your computer and use it in GitHub Desktop.
Save DZuz14/05e7fae272e0bf1b58f12cb4acc0924b to your computer and use it in GitHub Desktop.
Retrieve A Cookie With Javascript
function getCookie(cookieName) {
var name = cookieName + '='
var arr = document.cookie.split(';')
for (var i = 0; i < arr.length; i++) {
var str = arr[i]
while (str.charAt(0) === ' ') {
str = str.substring(1)
}
if (str.indexOf(name) === 0) {
return str.substring(name.length, str.length)
}
}
return ''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment