Created
June 3, 2013 16:03
-
-
Save bbrewer97202/5699204 to your computer and use it in GitHub Desktop.
cookie access via javascript starter
This file contains 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
var cookie = { | |
//session cookies | |
setCookie: function(name, value) { | |
document.cookie = name + "=" + escape(value) + ';path=/'; | |
}, | |
getCookie: function(name) { | |
var key, val; | |
var cookies = document.cookie.split(";"); | |
var cookiesLength = cookies.length; | |
for (var i=0; i < cookiesLength; i++) { | |
key = cookies[i].substr(0, cookies[i].indexOf("=")); | |
key = key.replace(/^\s+|\s+$/g, ""); | |
if (key === name) { | |
return cookies[i].substr(cookies[i].indexOf("=") + 1); | |
} | |
} | |
}, | |
cookieExists: function(name) { | |
return (cookie.getCookie(name)) ? true : false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment