Chinaunix首页 | 论坛 | 博客
  • 博客访问: 558612
  • 博文数量: 34
  • 博客积分: 10171
  • 博客等级: 上将
  • 技术积分: 1365
  • 用 户 组: 普通用户
  • 注册时间: 2004-11-09 13:13
文章分类

全部博文(34)

文章存档

2011年(1)

2009年(20)

2008年(13)

我的朋友

分类: 系统运维

2009-03-23 13:36:21

//设定Cookie值

function SetCookie(name, value)
{
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
//alert(path) ;

if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString())) +";path=/"+((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}
 SetCookie("setcookieabcsongname", "bbbb") ;

 

//读取COOKIE

//读取cookie中指定的内容
function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
                         
function GetCookie (name) {
         var arg = name + "=";
         var alen = arg.length;
         var clen = document.cookie.length;
         var i = 0;
         while (i < clen) {
             var j = i + alen;
             if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
             i = document.cookie.indexOf(" ", i) + 1;
             if (i == 0) break;
         }
         return null;
}

var geta2=GetCookie("a1");

阅读(535) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~