javascript cookie operations

Cookies

Definition: make your site server to store small amounts of data to the client's hard disk or memory, a technique hard to read data from a client;

Download and introduced: jquery.cookie.js based jquery; first introduced jquery, reintroduction: jquery.cookie.js; Download: http://plugins.jquery.com/cookie/

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>

1. Add a "session cookie"

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

There is no specified time valid cookie, the cookie is valid to create a default user closes the browser, it is called a "session cookie (session cookie)".

2. Create a cookie and set the effective time is 7 days

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

Here indicates the effective time cookie, the cookie is created called "persistent cookie (persistent cookie)". Note units are: days;

3. Create a cookie and set the cookie valid path

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

By default, only the cookie settings page in order to read the cookie. If you want a cookie page read another page setup, you must set a cookie path. The cookie path is used to set the cookie can read the top-level directory. The path to the root directory of the site, so that all the pages can be read each cookie (usually not this setting, prevent conflicts).

4. Read the cookie

$.cookie('the_cookie');

5. Delete cookie

$.cookie("this_value",null)

6. Optional parameters

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

the Expires : (Number The | a Date) is valid; set an integer, the unit is the day; can also set a date object as the expiration date of Cookie's;
path : (String) Create a Page path the Cookie's;
Domain : (String) created the Cookie page domain;
secure : (Booblean) If true, then the transmission of this Cookie will require a security protocol, for example: HTTPS;

 

Quote from: https: //www.cnblogs.com/webcome/p/5470975.html

Guess you like

Origin www.cnblogs.com/SandyZhao/p/10948356.html