Created
May 10, 2012 09:17
-
-
Save hiroshineya/2652063 to your computer and use it in GitHub Desktop.
get cookie with javascript
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
| // Cookie取得 | |
| // key:Cookie key | |
| // return: Cookie value. if not found, false. | |
| function getCookie(key){ | |
| if(key){ | |
| var cookieData = document.cookie + ";"; | |
| var startPoint1 = cookieData.indexOf(key); | |
| var startPoint2 = cookieData.indexOf("=",startPoint1)+1; | |
| var endPoint = cookieData.indexOf(";",startPoint1); | |
| if(startPoint2 < endPoint && startPoint1 > -1){ | |
| cookieData = cookieData.substring(startPoint2,endPoint); | |
| cookieData = cookieData; | |
| return cookieData; | |
| } | |
| } | |
| return false; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment