浏览器端cookie的取值和设值
来源:互联网 发布:php mysql 预编译 编辑:程序博客网 时间:2024/05/16 19:04
cookie各参数的理解:
name: COOKIE的名称
value: COOKIE的值
expires: COOKIE过期时间。指定cookie的生命期。 3600为一个小时
path: COOKIE保存的路径,指定与cookie关联的WEB页。值可以是一个目录,或者是一个路径。
domain: COOKIE指定关联的WEB服务器或域。值是域名
Secure: COOKIE的安全,指定cookie的值通过网络如何在用户和WEB服务器之间传递。这个属性的值或者是“secure”,或者为空。缺省情况下,该属性为空,也就是使用不安全的HTTP连接传递数据。如果一个 cookie 标记为secure,那么,它与WEB服务器之间就通过HTTPS或者其它安全协议传递数据。
demo: setCookies("name","value",{expires: 1, path: '/', secure: false});
==============WEB get 、set cookie的方法===============
//______
function getCookie(name) {
var cookie_start = document.cookie.indexOf(name);
var cookie_end = document.cookie.indexOf(";", cookie_start);
return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}
//________
function setCookies(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var path = options.path ? '; path=' + options.path : '';
var domain = options.domain ? '; domain=' + options.domain : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
}
0 0
- 浏览器端cookie的取值和设值
- DataKeysName的设值和取值
- redis(三)积累-基本的取值和设值
- CKEDITOR取值和设值
- 利用Javascript取和设FCKeditor值
- 利用Javascript取和设FCKeditor值
- 利用Javascript取和设FCKeditor值
- 利用Javascript取和设FCKeditor值
- 利用Javascript取和设FCKeditor值
- 利用Javascript取和设FCKeditor值
- 利用Javascript取和设FCKeditor值
- 利用cookie 记住背景颜色 (利用Jquery对Cookie进行设值与取值)
- FCK插件的取值,设值
- cookie的前台、后台存储和取值
- 用jquery为select取值和设值
- struts2中Action获得request、session、application进行设值和取值的方法
- struts2中Action获得request、session、application进行设值和取值的方法
- cookie存值和取值
- c++中两个类相互包含引用的相关问题
- C语言中的static变量和static函数
- Java四舍五入BigDecimal介绍
- mysql的使用23
- 结合使用 MongoDB 和 Django
- 浏览器端cookie的取值和设值
- 数据类型
- 傅利叶级数
- mysql的使用24
- Linux负载均衡软件LVS
- 关于win7下修改hosts文件提示无法保存的问题
- LinearLayout中组件右对齐
- Linux网络编程(1):TCP客户服务程序设计
- 通过excel向数据库(ORACLE)里插入数据