Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use jQuery.cookie.js

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge points about how to use jQuery.cookie.js. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

The cookie operation needs to be uploaded to the server to see that the result is not available locally.

A lightweight cookie plug-in that can read, write, and delete cookie.

Configuration of jquery.cookie.js

The library file for jQuery is included first, followed by the library file for jquery.cookie.js.

Usage

1. Add a new session cookie:

$.cookie ('the_cookie',' the_value')

Note: when the cookie validity period is not specified, the created cookie is valid by default until the user closes the browser, so it is called

Session cookie (session cookie).

two。 Create a cookie and set the validity period to 7 days:

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

Note: when the cookie validity time is specified, the cookie created is called "persistent cookie (persistent cookie)".

3. Create a cookie and set the valid path to cookie:

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

Note: by default, only web pages that set the cookie can read the cookie. If you want one page to read another page setting

To set the cookie, you must set the path of the cookie. The path to cookie is used to set the top-level directory that can read cookie. Put this

The path is set to the root directory of the site, so that all pages can read cookie from each other (generally do not set this to prevent conflicts).

4. Read cookie:

$.cookie ('the_cookie'); / / cookie exists = >' the_value' $.cookie ('not_existing'); / / cookie does not exist = > null

5. Delete cookie by passing null as the value of cookie:

$.cookie ('the_cookie', null)

-interpretation of relevant parameters-

1). Expires: 365

Defines the valid time of the cookie, which can be a number (in days from the time the cookie was created) or a Date pair

Elephant. If omitted, the cookie created is a session cookie and will be deleted when the user exits the browser.

2). Path:'/'

Default: only web pages that set the cookie can read the cookie.

Define a valid path to the cookie. By default, the value of this parameter is the path of the web page that created the cookie (the behavior of a standard browser).

If you want to access this cookie throughout the site, you need to set a valid path: path:'/'. If you want to delete a definition

The cookie of a valid path, which you need to include when calling the function: $.cookie ('the_cookie', null

{path:'/'});. Domain: 'example.com'

Default value: the domain name owned by the web page that created cookie.

3) .secure: true

Default value: false. If the transport for true,cookie requires the use of Security Protocol (HTTPS).

4). Raw: true

Default value: false.

By default, cookie is automatically encoded and decoded when it is read and written (using encodeURIComponent encoding

DecodeURIComponent decoding). To turn off this feature, set raw: true.

These are all the contents of the article "how to use jQuery.cookie.js". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report