jquery's actions on cookies

Source: Internet
Author: User
Tags set cookie

First step: Refer to jquery's plugin first jquery-1.9.1.min.js

Step two: Referencing the jquery.cookie.js plugin

The following actions on cookies:

 $.cookie ("CookieName", "Cookievalue", {expires:10, //  Effective date is in days if this item is not set then the browser will fail when it is closed  path: "/" // cookie path 
//,secure:true//default value: False. If the transport for True,cookie requires the use of security Protocol (HTTPS)
var cookieval = $.cookie ("CookieName"); // read cookie alert (cookieval); $.cookie ( "CookieName", "Cookieval"); // Set the cookie value if no cookie with the name CookieName is created $.cookie ( "CookieName", null ); // Delete cookie value

Compare the complete code:

1<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">234<title></title>5<script src= "Js/jquery-1.9.1.min.js" type= "Text/javascript" ></script>6<script src= "Jquery.cookie.js" type= "Text/javascript" ></script>7<script type= "Text/javascript" >8$(function () {9$ ("#CreateCookie"). Click (function() {//Write a cookieTen$.cookie ("CookieName", "Cookievalue", {expires:10,//valid date is in days if this item is not set then the browser will fail when it is closed OnePath: "/",//path of the cookie A                 }); -             }); -  the$ ("#readCookie"). Click (function () { -                 varCookieval = $.cookie ("CookieName");//Read Cookies - alert (cookieval); -             }); +  -$ ("#setCookieVal"). Click (function () { +$.cookie ("CookieName", "Cookieval");//sets the cookie value, if no cookie with the name CookieName is created A             }); at  -$ ("#delCookieVal"). Click (function () { -$.cookie ("CookieName",NULL);//Delete Cookie value -             }); -  -         }); in</script> - to<body> +<input type= "button" id= "Createcookie" value= "Create Cookie"/> -<input type= "button" id= "Readcookie" value= "read Cookie"/> the<input type= "button" id= "Setcookieval" value= "Set cookie"/> *<input type= "button" id= "Delcookieval" value= "Delete Cookie"/> $</body>Panax NotoginsengView Code

Explanation of the relevant parameters:
1, expires:365
Defines the effective time of a cookie, which can be a number (from the time the cookie is created, in days) or a Date object. If omitted, the cookie created is a session cookie that will be deleted when the user exits the browser.

2. Path: '/'
By default, only the Web page where the cookie is set can read the cookie. Defines a valid path for the cookie. By default, the value of this parameter is the path to the Web page where the cookie was created (the behavior of the 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 cookie that defines a valid path, you need to include this path when calling the function: $.cookie (' The_cookie ', null,{path: '/'});

3. Domain: ' example.com '
Default value: The domain name owned by the Web page that created the cookie.

4, Secure:true
Default value: False. If the transport for True,cookie requires the use of security Protocol (HTTPS).

5, Raw:true
Default value: False.
By default, the cookies are encoded and decoded automatically when they are read and written (using encodeURIComponent encoding, decodeuricomponent decoding). To turn this feature off, Raw:true can be set.

jquery's actions on cookies

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.