js读写cookie
来源:互联网 发布:西屋破壁机 知乎 编辑:程序博客网 时间:2024/05/19 03:43
JS读写COOKIE的方法!
var Cookies = {};
/**
* 设置Cookies
*/
Cookies.set = function(name, value){
var argv = arguments;
var argc = arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : '/';
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
};
/**
* 读取Cookies
*/
Cookies.get = function(name){
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
var j = 0;
while(i < clen){
j = i + alen;
if (document.cookie.substring(i, j) == arg)
return Cookies.getCookieVal(j);
i = document.cookie.indexOf(" ", i) + 1;
if(i == 0)
break;
}
return null;
};
/**
* 清除Cookies
*/
Cookies.clear = function(name) {
if(Cookies.get(name)){
var expdate = new Date();
expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
Cookies.set(name, "", expdate);
}
};
Cookies.getCookieVal = function(offset){
var endstr = document.cookie.indexOf(";", offset);
if(endstr == -1){
endstr = document.cookie.length;
}
return unescape(document.cookie.substring(offset, endstr));
};
/**
* 设置Cookies
*/
Cookies.set = function(name, value){
var argv = arguments;
var argc = arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : '/';
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
};
/**
* 读取Cookies
*/
Cookies.get = function(name){
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
var j = 0;
while(i < clen){
j = i + alen;
if (document.cookie.substring(i, j) == arg)
return Cookies.getCookieVal(j);
i = document.cookie.indexOf(" ", i) + 1;
if(i == 0)
break;
}
return null;
};
/**
* 清除Cookies
*/
Cookies.clear = function(name) {
if(Cookies.get(name)){
var expdate = new Date();
expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
Cookies.set(name, "", expdate);
}
};
Cookies.getCookieVal = function(offset){
var endstr = document.cookie.indexOf(";", offset);
if(endstr == -1){
endstr = document.cookie.length;
}
return unescape(document.cookie.substring(offset, endstr));
};
- JS读写cookie
- js 读写cookie
- js读写cookie
- js 读写cookie
- js读写cookie值
- js读写cookie
- JS 读写 Cookie 有关
- js Cookie 读写
- js读写cookie
- js读写cookie
- JS读写COokie
- js读写cookie
- js cookie读写
- js读写cookie
- js cookie读写
- js 读写 cookie
- js读写cookie
- js读写cookie
- ORACLE表被锁,解决方案
- 正则表达式用例
- 枚举进程,线程,模块,堆,设备
- time.h 函数说明
- Linux下无法加载动态库问题:cannot restore segment prot after reloc: Permission denied
- js读写cookie
- CSS常见的让元素水平居中显示方法
- PHP框架 Yii 1.0.9 发布
- 转载:IT行业中的常用ENGLISH
- typedef 的用法
- 提高WordPress速度与性能的技巧
- 在公司里写的一个自动启动Notes的小程序
- 敏捷开发简介
- FCKeditor jsp 配置 使用