Created
July 4, 2012 15:14
-
-
Save betawax/3047846 to your computer and use it in GitHub Desktop.
Create and retrieve cookies 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
function setCookie(name, value, path, expires) { | |
var date = new Date; | |
date.setTime(date.getTime()+(expires*24*60*60*1000)); | |
document.cookie = name+"="+value+";path="+path+";expires="+date.toGMTString(); | |
} | |
function getCookie(name) { | |
if (document.cookie) { | |
var value = document.cookie.split(name+"=")[1]; | |
if (value) { | |
return value.split(";")[0]; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Define the param "expires" in days.