Skip to content

Instantly share code, notes, and snippets.

@evanwalsh
Created May 3, 2009 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanwalsh/105824 to your computer and use it in GitHub Desktop.
Save evanwalsh/105824 to your computer and use it in GitHub Desktop.
// C IS FOR COOKIE originally by Mislav Marohnić ( http://mislav.uniqpath.com/js/c-is-for-cookie/ )
// chopped and spliced by Evan Walsh
var Cookie = {
find: function(name){
var name = escape(name) + '='
if (document.cookie.indexOf(name) >= 0) {
var cookies = document.cookie.split(/\s*;\s*/)
for (var i = 0; i < cookies.length; i++) {
if (cookies[i].indexOf(name) == 0)
return unescape(cookies[i].substring(name.length, cookies[i].length))
}
}
return null
},
create: function(name, value, options){
var newcookie = [escape(name) + "=" + escape(value)]
if (options){
if (options.expires) newcookie.push("expires=" + options.expires.toGMTString())
if (options.path) newcookie.push("path=" + options.path)
if (options.domain) newcookie.push("domain=" + options.domain)
if (options.secure) newcookie.push("secure")
}
document.cookie = newcookie.join('; ')
return true
},
destroy: function(name){
document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;'
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment