JavaScript js cookies store, get and delete _javascript tips

Source: Internet
Author: User
Tags reserved set cookie setcookie
How to use:

1. Storing cookies
2, Parameter Description: 1, parameter 1:cookie store name, parameter 2:cookie the value to store
3. Examples are as follows:
Setcookie (' method ', match);

1. Get cookies
2, Parameter Description: 1, parameter 1:cookie store name
3. Examples are as follows:
GetCookie (' method ')

1, delete cookies
2, Parameter Description: 1, parameter 1:cookie store name
3. Examples are as follows:
Deletecookie (' method ');

The functions are as follows:

Copy Code code as follows:

<script language=javascript>
/**//************************************************************************
| Function Name: Setcookie |
| function function: Set cookie function |
| Entry parameters: Name:cookie name; Value:cookie value |
| Maintenance Record: Spark (Create) |
| All rights reserved: (C) 2006-2007 Beijing Oriental Changzhi Technology Co., Ltd. |
| Written Date: September 13, 2007 21:00 |
*************************************************************************/
function Setcookie (name, value)
... {
var argv = setcookie.arguments;
var argc = setCookie.arguments.length;
var expires = (argc > 2)? ARGV[2]: null;
if (expires!=null)
... {
var largeexpdate = new Date ();
Largeexpdate.settime (Largeexpdate.gettime () + (expires*1000*3600*24));
}
Document.cookie = name + "=" + Escape (value) + ((expires = null)? "" : ("; Expires= "+largeexpdate.togmtstring ()));
}
/**//************************************************************************
| Function Name: GetCookie |
| function function: Read Cookie function |
| Entry parameters: Name:cookie name |
| Maintenance Record: Spark (Create) |
| All rights reserved: (C) 2006-2007 Beijing Oriental Changzhi Technology Co., Ltd. |
| Written Date: September 13, 2007 21:02 |
*************************************************************************/
function GetCookie (Name)
... {
var search = Name + "="
if (Document.cookie.length > 0)
... {
offset = document.cookie.indexOf (search)
if (offset!=-1)
... {
Offset + = Search.length
End = Document.cookie.indexOf (";", offset)
if (end = = 1) end = Document.cookie.length
return unescape (offset, end) (document.cookie.substring)
}
else return ""
}
}

/**//************************************************************************
| Function Name: Deletecookie |
| function function: Delete Cookie function |
| Entry parameters: Name:cookie name |
| Maintenance Record: Spark (Create) |
| All rights reserved: (C) 2006-2007 Beijing Oriental Changzhi Technology Co., Ltd. |
| Written Date: September 15, 2007 18:10 |
*************************************************************************/
function Deletecookie (name)
... {
var expdate = new Date ();
Expdate.settime (Expdate.gettime ()-(86400 * 1000 * 1));
Setcookie (Name, "", expdate);
}
</script>
Related Article

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.