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 to operate Cookies

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge of "how to use Jquery to operate Cookies". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Cookies, also known as Cookie,Cookies, is a technology that allows a web server to store a small amount of data in the client's hard disk or memory, or read data from the client's hard disk.

Download and import: jquery.cookie.js based on jquery; first introduces jquery, and then introduces: jquery.cookie.js

First, create Cookies1. Create or set cookie value: $.cookie ('the_cookie',' the_value')

The cookie validity period is not specified here, and 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})

The cookie validity time is indicated here, and the cookie created is called "persistent cookie (persistent cookie)". Note that the unit is: days

3. Create a cookie and set the valid path to cookie $.cookie ('the_cookie',' the_value', {expires: 7, path:'/'})

By default, only Web pages that set the cookie can read the cookie. If you want one page to read the cookie of another page setup, you must set the path to the cookie. The path to cookie is used to set the top-level directory that can read cookie. Setting this path to the root of the site allows all pages to read cookie from each other (generally not to prevent conflicts).

4. Optional parameter $.cookie ('the_cookie','the_value', {expires:7, path:'/', domain:'jquery.com', secure:true})

Expires: (Number | Date) validity period. When you set an integer, the unit is days. You can also set a date object as the expiration date of Cookie.

Path: (String) create the page path of the Cookie

Domain: (String) create the page domain name of the Cookie

Secure: (Booblean) if set to true, then the transmission of this Cookie requires a security protocol, such as HTTPS

Second, read cookie$.cookie ('the_cookie'); third, delete cookie

It is recommended to configure the path and domain name when setting up cookie and deleting cookie.

$.cookie ('the_cookie', null); / / $.cookie (' name',null, {path:'/'}) by passing null as the value of Cookies ('cookie, {cookie: /'}); that's all for "how to use Jquery to operate cookie". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Development

Wechat

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

12
Report