# jquery.cookie [](https://travis-ci.org/carhartl/jquery-cookie)
A simple, lightweight jQuery plugin for reading, writing and deleting cookies.
## Installation
Include script *after* the jQuery library (unless you are packaging scripts somehow else):
<script src="/path/to/jquery.cookie.js"></script>
**Do not include the script directly from GitHub (http://raw.github.com/...).** The file is being served as text/plain and as such being blocked
in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). Bottom line: GitHub is not a CDN.
The plugin can also be loaded as AMD module.
## Usage
Create session cookie:
$.cookie('the_cookie', 'the_value');
Create expiring cookie, 7 days from then:
$.cookie('the_cookie', 'the_value', { expires: 7 });
Create expiring cookie, valid across entire site:
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });
Read cookie:
$.cookie('the_cookie'); // => "the_value"
$.cookie('not_existing'); // => undefined
Read all available cookies:
$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" }
Delete cookie:
// Returns true when cookie was found, false when no cookie was found...
$.removeCookie('the_cookie');
// Same path as when the cookie was written...
$.removeCookie('the_cookie', { path: '/' });
*Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie, unless you're relying on the default options that is.*
## Configuration
### raw
By default the cookie value is encoded/decoded when writing/reading, using `encodeURIComponent`/`decodeURIComponent`. Bypass this by setting raw to true:
$.cookie.raw = true;
### json
Turn on automatic storage of JSON objects passed as the cookie value. Assumes `JSON.stringify` and `JSON.parse`:
$.cookie.json = true;
## Cookie Options
Cookie attributes can be set globally by setting properties of the `$.cookie.defaults` object or individually for each call to `$.cookie()` by passing a plain object to the options argument. Per-call options override the default options.
### expires
expires: 365
Define lifetime of the cookie. Value can be a `Number` which will be interpreted as days from time of creation or a `Date` object. If omitted, the cookie becomes a session cookie.
### path
path: '/'
Define the path where the cookie is valid. *By default the path of the cookie is the path of the page where the cookie was created (standard browser behavior).* If you want to make it available for instance across the entire domain use `path: '/'`. Default: path of page where the cookie was created.
**Note regarding Internet Explorer:**
> Due to an obscure bug in the underlying WinINET InternetGetCookie implementation, IE’s document.cookie will not return a cookie if it was set with a path attribute containing a filename.
(From [Internet Explorer Cookie Internals (FAQ)](http://blogs.msdn.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx))
This means one cannot set a path using `path: window.location.pathname` in case such pathname contains a filename like so: `/check.html` (or at least, such cookie cannot be read correctly).
### domain
domain: 'example.com'
Define the domain where the cookie is valid. Default: domain of page where the cookie was created.
### secure
secure: true
If true, the cookie transmission requires a secure protocol (https). Default: `false`.
## Tests
Requires Node. Startup server:
$ node test/server.js
Open in browser:
$ open http://0.0.0.0:8124/test/index.html
For quick *non cross-browser* testing use grunt, install grunt CLI and project dependencies as outlined in this guide: <http://gruntjs.com/getting-started>, then run:
$ grunt
## Development
- Source hosted at [GitHub](https://github.com/carhartl/jquery-cookie)
- Report issues, questions, feature requests on [GitHub Issues](https://github.com/carhartl/jquery-cookie/issues)
Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change you make.
## Authors
[Klaus Hartl](https://github.com/carhartl)
没有合适的资源?快使用搜索试试~ 我知道了~
jquery-cookie-master.zip_The Master_cookie

共16个文件
js:4个
json:3个
html:2个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 6 浏览量
2022-09-24
05:10:36
上传
评论
收藏 11KB ZIP 举报
温馨提示
jQuery操作cookie的插件,大概的使用方法如下 $.cookie( the_cookie ) //读取Cookie值 $.cookie(’the_cookie’, ‘the_value’) //设置cookie的值 $.cookie(’the_cookie’, ‘the_value’, {expires: 7, path: ‘/’, domain: ‘jquery.com’, secure: true}) //新建一个cookie 包括有效期 路径 域名等 $.cookie(’the_cookie’, ‘the_value’) //新建cookie $.cookie(’the_cookie’, null) //删除一个cookie
资源推荐
资源详情
资源评论




























收起资源包目录



















共 16 条
- 1
资源评论


邓凌佳
- 粉丝: 96
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 基于SNA的突发网络事件传播关系研究.docx
- 基于BP神经网络结构的图像压缩技术研究.docx
- 雾计算:概念、框架与技术解析
- 计算机硬件维护的关键技术.docx
- 计算机教学探索.docx
- 动态网站“网络商城购物”的方案设计书与实现.doc
- 如何在虚拟机中安装WINCC软件.doc
- PROE、AutoCAD的三维图及二维图练习.doc
- 【公开课】基因工程及其应用.ppt
- 初中生家庭网络安全教育的初步探讨.docx
- 计算机(网络)维修申请单.doc
- 单片机简易频率计课程设计方案.docx
- 大数据时代高校图书馆学科服务转型升级探索.docx
- 单片机综合方案设计书开关状态显示控制.doc
- 刍议计算机病毒与反病毒技术研究.docx
- 计科级、物联网级秋季数据库课程设计计划[New].doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
