Home > Web Front-end > JS Tutorial > javascript js cookie storage, acquisition and deletion_javascript skills

javascript js cookie storage, acquisition and deletion_javascript skills

WBOY
Release: 2016-05-16 19:06:52
Original
917 people have browsed it

Usage:

//1. Store Cookie
//2. Parameter description: 1. Parameter 1: Cookie storage Name, Parameter 2: Value to be stored in Cookie
//3. Example As follows:
setCookie('Method',match);

//1. Get Cookie
//2. Parameter Description: 1. Parameter 1: Name stored in Cookie
// 3. Examples are as follows:
getCookie('Method')

//1. Delete Cookie
//2. Parameter description: 1. Parameter 1: Name of cookie storage
// 3. The example is as follows:
deleteCookie('Method');


The function is as follows:

Copy the code The code is as follows:

 
/**//************************************************ **********************
| Function name: setCookie                                                                               : name: cookie name; value: cookie value |
| Maintenance record: Spark (created) 006-2007 Beijing Oriental Changzhi Technology Co., Ltd.                                                            : 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                                                                            Parameters: Name: cookie name                                                                                                             🎜>| Copyright: (C) 2006-2007 Beijing Oriental Changzhi Technology Co., Ltd. |
| Writing time: September 2007 March 13th 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(document.cookie.substring(offset, end))  
       }  
       else return ""  
   }  
}  

/**//************************************************ **********************
| Function name: deleteCookie                                                                                                                       : Name:cookie name                                                                                                     : (C) 2006-2007 Beijing Oriental Changzhi Technology Co., Ltd. |
| Writing time: September 2007 15th 18:10                                                    ********************************/     
function deleteCookie(name)  
...{  
                    var expdate = new Date();  
                    expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));  
   setCookie(name, "", expdate);  
}  


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template