欢迎光临

木子屋

标题: cookie封装

作者: dnawo

日期: 2008-01-07 10:22 AM

分类: 脚本语言

内容: 复制内容到剪贴板 程序代码//来源：无忧脚本(http://bbs.51js.com/viewthread.php?tid=75292)
function Cookie()
{
this.set = function(name,value,days,domain,path,secure){
var str = name + "=" + escape(value) + ";";
if(days) str += "expires="+new Date(new Date().getTime() + days*86400000).toGMTString()+"; ";
if(domain)str+="domain="+domain+"; ";
if(path)str+="path="+path+"; ";
if(secure)str+="secure;" ;
document.cookie=str;
}
this.get = function(name){
var value = "";
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) { value=unescape(arr[2]); }
return value;
}
this.del = function(name){
document.cookie=name + "=;expires="+new Date().toGMTString();
}
this.toString=function(){
var cookies=document.cookie.split("; ");
for(var i=0;i<cookies.length;i++)
{
var s=cookies[i].split("=");
if(s[0]==name)return unescape(s[1]);
}
}
}
复制内容到剪贴板 程序代码//来源：QQ空间(http://270250392.qzone.qq.com/)
function setFileCookie(name,value,timeout,dm){
var expires=new Date();
if(!timeout)timeout=10*12*30*24*3600*1000;
if(!dm)dm="qq.com";
expires.setTime(expires.getTime()+timeout);
document.cookie=name+"="+value+";expires="+expires.toGMTString()+"; path=/; domain="+dm;

}
function setCookie(name,value,path,domain){
if(!path)path="/";
if(!domain)domain="qq.com";
document.cookie=name+"="+value+"; path="+path+"; domain="+domain;

}
function getCookie(name){
var r=new RegExp("(\\b)"+name+"=([^;]*)(;|$)");
var m=document.cookie.match(r);
return (!m?"":m[2]);

}
function deleteCookie(name,path,domain){
if(!path)path="/";
if(!domain)domain="qq.com";
document.cookie=name+"="+"; path="+path+"; domain="+domain+"; expires=Thu,1 Jan 1970 00:00:01 UTC";

}

+ 查看当前日志评论 (0)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 1.523 ms

返回

标题: cookie封装

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 1.523 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 1.555 ms

返回