Skip to content

Instantly share code, notes, and snippets.

@iamjwc
Created May 25, 2011 15:37
Show Gist options
  • Save iamjwc/991193 to your computer and use it in GitHub Desktop.
Save iamjwc/991193 to your computer and use it in GitHub Desktop.
# From: http://www.quirksmode.org/js/cookies.html
window.CookieHelpers =
expiry: (days) ->
date = new Date
date.setTime(date.getTime()+(days*24*60*60*1000))
"; expires=#{date.toGMTString()}"
write: (name, value, days) ->
expires = if days then this.expiry(days) else ""
document.cookie = "#{name}=#{value}#{expires}; path=/"
read: (name) ->
nameEQ = "#{name}="
ca = document.cookie.split(';')
for i in [i...ca.length]
return match[1] if match = ca[i].match(/name=(.*)$/)
erase: (name) ->
CookieHelpers.write(name, "", -1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment