js中cookies 的用法以及在.NET中的引用
来源:互联网 发布:linux 竖条 编辑:程序博客网 时间:2024/06/05 11:38
jquery.cookie.js源码
/**
* Cookie plugin
*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
/**
* Create a cookie with the given name and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
* used when the cookie was set.
*
* @param String name The name of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
/**
* Get the value of a cookie with the given name.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String name The name of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
jQuery.cookie = function(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
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
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;
}
};
query.cookie.js 提供了jquery中非常简单的操作cookie的方法。$.cookie('the_cookie'); // 获得cookie
$.cookie('the_cookie', 'the_value'); // 设置cookie
$.cookie('the_cookie', 'the_value', { expires: 7 }); //设置带时间的cookie
$.cookie('the_cookie', '', { expires: -1 }); // 删除
$.cookie('the_cookie', null); // 删除 cookie
$.cookie(’the_cookie’, ‘the_value’, {expires: 7, path: ‘/’, domain: ‘jquery.com’, secure: true});//新建一个cookie 包括有效期 路径 域名等
以下是.NET中的引用
HttpCookieCollection cookies;
HttpCookie oneCooke;
cookies = Request.Cookies;
string[] cookieArray = cookies.AllKeys;
System.IO.StringWriter writer = new System.IO.StringWriter();
for (int i = 0; i < cookieArray.Length; i++)
{
oneCooke = cookies[cookieArray[i]];
Server.UrlDecode(oneCooke.Value, writer);
lblMessage.Text += oneCooke.Name + "---->>" + writer.ToString() + "------>>";
}
- js中cookies 的用法以及在.NET中的引用
- C#中OutlookBar的使用以及在项目中的引用
- asp.net cookies的用法
- ASP.NET-Cookies的用法
- QT中动态链接库的建立,以及在QT中的引用,C++程序中的引用
- QT中动态链接库的建立,以及在QT中的引用,C++程序中的引用
- AngularJs中$cookies的用法
- JS 中 cookies 的使用
- Cookies在asp.net中得应用
- JS中continue在while循环、do-while循环以及for循环中的用法
- 简述一下二级指针以及指针的引用在结构体中用法
- Asp.net Cookies用法
- asp.net cookies用法
- 在js中引用图片的写法
- 在js中引用图片的写法
- 怎么在ASP.NET中引用JS文件
- asp 中的cookies用法
- java web中cookies的用法 转
- 给Tomcat增加可用内存
- 深入分析Windows和Linux动态库应用异同
- facebook 的工程师文化 zz自bing8848
- ef + oracle 中文出错解决方法
- Gentoo Linux安装纪要之后传
- js中cookies 的用法以及在.NET中的引用
- mj评-《整编特工》8分
- qt中关于QWidget的背景颜色和背景图片的设置
- 给文字块添加提示框
- 大数据量场景加速绘制基本原理与方法
- 一个无敌删除命令
- 10句编程谚语
- U-Boot的常用命令详解
- 简明批处理教程