Oct 29
var Cookies={set:function(n,v,d){var g="";if(d!=undefined){var f=new Date();f.setTime(f.getTime()+(d*24*60*60*1000));g="; expires="+f.toGMTString();};document.cookie=escape(n)+"="+escape(v||'')+g;},get:function(n){var a=n+"=";var r=null;document.cookie.split(';').each(function(s){while(s.charAt(0)==' ')s=s.substring(1,s.length);if(s.indexOf(a)==0)r=s.substring(a.length,s.length);});return r;},remove:function(n){this.set(n,'',-1);return this.get(n)||true;}};
RequireMent
Prototype Framework (http://www.prototypejs.org)
Usage
Cookies.set(name, value, expired date);
Cookies.get(name);
Cookies.remove(name);
10월 29th, 2007 at 2:19 오후
우왕…. 뭔말인지 모르겟다능.. ㅠㅠ 자바스크립트 어려움..
1월 18th, 2008 at 1:15 오전
Thanks! Nice and powerfull Snippet :)
ps.: I added a `return unescape(r);` to the get-Function .. because the cookie-content get escaped when setted.
2월 11th, 2008 at 6:17 오후
Thanks to coming my blog :]
3월 30th, 2008 at 6:24 오후
does anyone knows if there is any other information about this subject in other languages?