JQuery.Cookie_V1.4.1前端辅助工具,跨页面记录用户的操作习惯!

## Installation

Include script *after* the jQuery library (unless you are packaging scripts somehow else):

```html

<script src="/path/to/jquery.cookie.js"></script> 

```

## Usage

Create session cookie:

```javascript

$.cookie(‘the_cookie‘, ‘the_value‘); 

```

Create expiring cookie, 7 days from then:

```javascript

$.cookie(‘the_cookie‘, ‘the_value‘, { expires: 7 }); 

```

Create expiring cookie, valid across entire site:

```javascript

$.cookie(‘the_cookie‘, ‘the_value‘, { expires: 7, path: ‘/‘ });

```

Read cookie:

```javascript

$.cookie(‘the_cookie‘); // => "the_value" $.cookie(‘not_existing‘); // => undefined 

```

Read all available cookies:

```javascript

$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" }

```

Delete cookie:

```javascript

// 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:

```javascript $.cookie.raw = true; ```

### json

Turn on automatic storage of JSON objects passed as the cookie value. Assumes `JSON.stringify` and `JSON.parse`:

```javascript $.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`.

## Converters

Provide a conversion function as optional last argument for reading, in order to change the cookie‘s value to a different representation on the fly.

Example for parsing a value into a number:

```javascript $.cookie(‘foo‘, ‘42‘); $.cookie(‘foo‘, Number); // => 42 ```

Dealing with cookies that have been encoded using `escape` (3rd party cookies):

```javascript $.cookie.raw = true; $.cookie(‘foo‘, unescape); ```

You can pass an arbitrary conversion function.

## Contributing

Check out the [Contributing Guidelines](CONTRIBUTING.md)

## Authors

[Klaus Hartl](https://github.com/carhartl)

时间: 2024-08-29 05:42:46

JQuery.Cookie_V1.4.1前端辅助工具,跨页面记录用户的操作习惯!的相关文章

优秀网站看前端 —— 小米Note介绍页面

刚开始经营博客的时候,我写过不少“扒皮”系列的文章,主要介绍一些知名站点上有趣的交互效果,然后试着实现它们.后来开始把注意力挪到一些新颖的前端技术上,“扒皮”系列便因此封笔多时.今天打算重开“扒皮”的坑,不过咱挂个优雅点的名字——“优秀网站看前端”,顾名思义的,也是寻觅一些值得玩味的趣味网站,来学习它们的前端技术和交互理念. 作为本系列的开篇,我们拿“买手机送国土”的小米来打头阵,缘由是鄙人有着更换手机的打算又刚好看上小米note高配版,于是逛了下小米note的介绍页面,感觉交互做的挺不错,特别

前端辅助开发工具积累

一.IDE 1)Edit Plus 2)Notepad++ 3)Dreamweaver 4)ultraedit 二.浏览器插件 1)IE Developer Toolbar(布局样式,脚本调试,性能分析) 2)Firebug(布局样式,脚本调试,性能分析) 3)chrome developer tools(布局样式,脚本调试,性能分析) 4)HTML Validator(通过FF的附加工具中添加插件,验证html的是否满足w3c的合法性) 三.其他辅助工具 1)PngOptimizer(压缩pn

前端自动化工具 -- grunt 使用简介

grunt是什么,grunt就是个东西.. grunt作为一个前端构建工具,有资源压缩,代码检查,文件合并等功能. 下面就简单了解grunt的使用. 一.环境配置 grunt是基于nodejs的,所以需要一个 nodejs 环境,未了解的可以 来这看看 还是在windows下, 首先要保证grunt命令可以使用,所以要先使用npm安装对应CLI npm install -g grunt-cli 安装完成可以命令行中输入“grunt”测试是否安装成功 安装成功后 二.用法说明 grunt需要pac

前端实用工具链接

前端实用工具链接 JavaScript 库 Particles.js ?- 一个用于在网页上创建漂亮的浮动粒子的 JS 库: Three.js ?- 用于在网页上创建 3D 物体与空间的 JS 库: Fullpage.js - 易于实现全屏滚动功能的库: Typed.js - 实现打字机效果: Waypoints.js - 滚动到元素触发事件的库: Highlight.js - 页面上语法高亮显示: Chart.js - 纯 JS 制作漂亮的图表: Instantclick - 鼠标悬停预先加载

前端构建工具gulpjs的使用介绍及技巧

gulpjs是一个前端构建工具,与gruntjs相比,gulpjs无需写一大堆繁杂的配置参数,API也非常简单,学习起来很容易,而且gulpjs使用的是nodejs中stream来读取和操作数据,其速度更快.如果你还没有使用过前端构建工具,或者觉得gruntjs太难用的话,那就尝试一下gulp吧. 本文导航: gulp的安装 开始使用gulp gulp的API介绍 一些常用的gulp插件 1.gulp的安装 首先确保你已经正确安装了nodejs环境.然后以全局方式安装gulp: npm inst

前端构建工具gulpjs的使用介绍及技巧(转载)

本文转载自无双 ,原文地址 http://www.cnblogs.com/2050/p/4198792.html. 感谢原博主的辛苦总结. gulpjs是一个前端构建工具,与gruntjs相比,gulpjs无需写一大堆繁杂的配置参数,API也非常简单,学习起来很容易,而且gulpjs使用的是nodejs中stream来读取和操作数据,其速度更快.如果你还没有使用过前端构建工具,或者觉得gruntjs太难用的话,那就尝试一下gulp吧. 本文导航: gulp的安装 开始使用gulp gulp的AP

前端构建工具gulpjs

gulpjs是一个前端构建工具,与gruntjs相比,gulpjs无需写一大堆繁杂的配置参数,API也非常简单,学习起来很容易,而且gulpjs使用的是nodejs中stream来读取和操作数据,其速度更快. 1.安装 首先确保你已经正确安装了nodejs环境.然后以全局方式安装gulp: npm install -g gulp 全局安装gulp后,还需要在每个要使用gulp的项目中都单独安装一次.把目录切换到你的项目文件夹中,然后在命令行中执行: npm install gulp 如果想在安装

前端模块化工具-webpack

详解前端模块化工具-webpack webpack是一个module bundler,抛开博大精深的汉字问题,我们暂且管他叫'模块管理工具'.随着js能做的事情越来越多,浏览器.服务器,js似乎无处不在,这时,使日渐增多的js代码变得合理有序就显得尤为必要,也应运而生了很多模块化工具.从服务器端到浏览器端,从原生的没有模块系统的`<script>`到基于Commonjs和AMD规范的实现到ES6 modules.为了模块化和更好的模块化,我们总是走在探索的路上. 但是这些实现模块化的方法或多或

一个前端开发工具

最近一直在琢磨着做一个前端开发工具,自身需求如下: 1. 开源 2. 基于Jquery和bootstrap 3. 所见即所得 4. 良好的扩展性 5. WinForm程序 昨天搭了一个框架出来,发现比我想像的工作量还要大一些. 本来我个人的人生哲学是“知难而退”,可是又想想出来混了这么多年,用了人家多少代码,是该还的时候了,尽早的事儿. 所以下定决心,准备坚持一下. 没钱就不能干点活了,什么社会啊?