jquery Operation Cookie

Source: Internet
Author: User
Tags valid

Jquery.cookie.js is a jquery based plug-in that can be downloaded online and is no longer available here.

Create a session Cookie:

$.cookie (' cookiename ', ' cookievalue ');

Note: When no cookie time is specified, the cookie that is created is known as the session cookie by default to the user's browser shutdown.

To create a persistent cookie:

$.cookie (' cookiename ', ' Cookievalue ', {expires:7});

Note: When the time is specified, it is called a persistent cookie and the valid time is days.

Create a cookie that is persistent and with a valid path:

$.cookie (' cookiename ', ' Cookievalue ', {expires:7,path: '/'});

Note: If you do not set a valid path, by default, only the path to read the Cookie,cookie on the cookie Settings current page is used to set up a top-level directory that can read cookies.

Create a cookie that is persistent and with a valid path and domain name:

$.cookie (' cookiename ', ' Cookievalue ', {expires:7,path: '/', Domain: ' chuhoo.com ', secure:false,raw:false});

Note: domain: Create the name of the Web page owned by the cookie; secure: Default is False, if the transport protocol for True,cookie is Https;raw: Default to False, encoding and decoding automatically when reading and writing ( Use encodeuricomponent encoding, use decodeuricomponent decoding), turn off this feature, set to true.

Get cookies:

$.cookie (' cookiename '); Returns Cookievalue if present, otherwise null is returned.

To delete a cookie:

$.cookie (' cookiename ', null);

Note: If you want to delete a cookie with a valid path, the following: $.cookie (' CookieName ', Null,{path: '/'});

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.