Jquery.cookie Introduction and Usage

Source: Internet
Author: User
Tags jquery library

1, rely on jquery library 2, browser compatibility situation

3. Download

Official Github:https://github.com/carhartl/jquery-cookie

4. Use
    • Create an entire site cookie
$.cookie(‘name‘, ‘value‘);
    • 1
    • Create an entire site cookie that is valid for 7 days
$.cookie(‘name‘, ‘value‘, { expires: 7 });
    • 1
    • Create a cookie that is valid only for the path path page, and the cookie is valid for 7 days
$.cookie(‘name‘, ‘value‘, { expires: 7, path: ‘/‘ });
    • 1
    • Read cookies
$.cookie(‘name‘); // 如果cookie存在 则获取到cookie值 => ‘value‘$.cookie(‘nothing‘); // 如果cookie不存在 则返回 => undefined
    • 1
    • 2
    • Get all the visible cookies
$.cookie(); // 数据格式 => { name: ‘value‘ }
    • 1
    • Delete Cookies
$.removeCookie(‘name‘); // => true$.removeCookie(‘nothing‘); // => false
    • 1
    • 2
    • Delete a cookie with attributes
$.cookie(‘name‘, ‘value‘, { path: ‘/‘ });// 错误$.removeCookie(‘name‘); // => false// 正确$.removeCookie(‘name‘, { path: ‘/‘ }); // => true
    • 1
    • 2
    • 3
    • 4
    • 5
5. Attribute domain

Create a domain name owned by the Web page where the cookie resides

$.cookie(‘name‘, ‘value‘, { domain: ‘weber.pub‘ });
    • 1
Secure

The default is False if the transport protocol for True,cookie needs to be https;

$.cookie(‘name‘, ‘value‘, { secure: true });$.cookie(‘name‘); // => ‘value‘$.removeCookie(‘name‘, { secure: true }); 
    • 1
    • 2
    • 3
Raw

The default is False, the read and write time is automatically encoded and decoded (using encodeURIComponent encoding, using decodeuricomponent decoding), turn off this function, set to TRUE.

$.cookie.raw = true;
    • 1
Json
$.cookie.json = true;

Jquery.cookie Introduction and Usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.