[jQuery] Cookie 플러그인
컴터/jQuery 2009/01/23 10:44 |(function($){
$.cookie = function(key, value, options) {
if(arguments.length > 1) {
var o = $.extend({}, $.cookie.defaults, options);
if (value === null || value === undefined) {
value = '';
o.expires = -1;
}
if (o.expires.constructor != Date) {
var today = new Date();
today.setDate(today.getDate() + o.expires);
o.expires = today;
}
// Create the cookie string
document.cookie =
key + '=' + value +
'; expires=' + o.expires.toUTCString() +
(o.path? '; path=' + (o.path) : '') +
(o.domain? '; domain=' + (o.domain) : '') +
(o.secure? '; secure' : '');
} else {
if(result = new RegExp(key+"=(.*?)(?:;|$)").exec(document.cookie))
return decodeURIComponent(result[1]);
return false;
}
};
$.cookie.defaults = {
expires: 365,
path: '/'
}
})(jQuery);
사용법 : $.cookie(키, 값, 옵션);
옵션은 {expires:'',domain:'', path:'', secure:''}
예 : $.cookie('key', 'ok', {expires:7,domain:'.myhost.com', path:'/', secure:0});
expires는 日단위..
뽑아오기 : alert($.cookie('happy_new_expire'));
'컴터 > jQuery' 카테고리의 다른 글
| [jQuery]form plugin - ajaxForm(options) 활용예제 (0) | 2009/03/24 |
|---|---|
| [jQuery] 위아래로 따라다니는 퀵메뉴 (0) | 2009/03/23 |
| jQuery로 부른 아이디 객체 역으로 아이디명 빼오기 (0) | 2009/02/15 |
| [jQuery] Cookie 플러그인 (2) | 2009/01/23 |
| jQuery 와 prototype 과 같이 사용시.. (0) | 2009/01/22 |
댓글을 달아 주세요
좋은 정보 감사합니다. 담아갈께요^^;
별 말씀을 ^^