Created
January 29, 2014 16:46
-
-
Save ckng/8691983 to your computer and use it in GitHub Desktop.
snippet: javascript to get cookie
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getCookie(name) { | |
name = name.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); | |
var regex = new RegExp('(?:^|;)\\s?' + name + '=(.*?)(?:;|$)','i'), | |
match = document.cookie.match(regex); | |
return match && unescape(match[1]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment