Created
June 2, 2014 06:34
-
-
Save leonguyen/53c2d5fe516fb6c6acd0 to your computer and use it in GitHub Desktop.
Get, Set and Print Cookies
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(w){ | |
| cName = ""; | |
| pCOOKIES = new Array(); | |
| pCOOKIES = document.cookie.split('; '); | |
| for(bb = 0; bb < pCOOKIES.length; bb++){ | |
| NmeVal = new Array(); | |
| NmeVal = pCOOKIES[bb].split('='); | |
| if(NmeVal[0] == w){ | |
| cName = unescape(NmeVal[1]); | |
| } | |
| } | |
| return cName; | |
| } | |
| function printCookies(w){ | |
| cStr = ""; | |
| pCOOKIES = new Array(); | |
| pCOOKIES = document.cookie.split('; '); | |
| for(bb = 0; bb < pCOOKIES.length; bb++){ | |
| NmeVal = new Array(); | |
| NmeVal = pCOOKIES[bb].split('='); | |
| if(NmeVal[0]){ | |
| cStr += NmeVal[0] + '=' + unescape(NmeVal[1]) + '; '; | |
| } | |
| } | |
| return cStr; | |
| } | |
| function setCookie(name, value, expires, path, domain, secure){ | |
| document.cookie = name + "=" + escape(value) + "; "; | |
| if(expires){ | |
| expires = setExpiration(expires); | |
| document.cookie += "expires=" + expires + "; "; | |
| } | |
| if(path){ | |
| document.cookie += "path=" + path + "; "; | |
| } | |
| if(domain){ | |
| document.cookie += "domain=" + domain + "; "; | |
| } | |
| if(secure){ | |
| document.cookie += "secure; "; | |
| } | |
| } | |
| function setExpiration(cookieLife){ | |
| var today = new Date(); | |
| var expr = new Date(today.getTime() + cookieLife * 24 * 60 * 60 * 1000); | |
| return expr.toGMTString(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment