比这篇新的文章: 发芽网的全站都在用的css
比这篇旧的文章: Python生成Gravatar url的函数

Javascript cookie操作函数set, get & delete

语言: JavaScript, 标签: cookie 发芽网 2008/05/23发布 1年前更新 更新记录
作者: 半瓶墨水, 点击1691次, 评论(0), 收藏者(1), , 打分:

背景
主题: 字体:
01 /*发芽网试用的cookie相关函数*/
02 function set_cookie(key, value, exp, path, domain, secure )
03 {
04   var cookie_string = key + "=" + escape ( value );
05   if (exp)
06   {
07     cookie_string += "; expires=" + exp.toGMTString();
08   }
09   if (path)
10     cookie_string += "; path=" + escape(path);
11   if (domain)
12     cookie_string += "; domain=" + escape(domain);
13   if (secure)
14     cookie_string += "; secure";
15   document.cookie = cookie_string;
16 }
17
18 function get_cookie(cookie_name)
19 {
20   var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
21
22   if (results)
23     return (unescape(results[2]));
24   else
25     return null;
26 }
27
28 function delete_cookie(cookie_name)
29 {
30   var cookie_date = new Date(); //current date & time
31   cookie_date.setTime(cookie_date.getTime() - 1);
32   document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
33 }


所有评论,共0条:( 我也来说两句)


发表评论

注册登录后再发表评论