Js operation Cookie Summary (set, read, and delete), which is often used at work! Below is the detailed code. If there is an error, please leave a message to correct it!
/** Function: Set the required Cookie * cookieName, the required cookie name * cookieValue, And the cookie value * seconds survival time. Optional. Unit: seconds; the default time is 3600 seconds * path cookie storage path, which can be * domain cookie domain, optional * secure security, specifying whether the Cookie can only be accessed through https, general cookies can be accessed using the HTTP protocol. If Secure (no value) is set, the Cookie can be accessed by the page only when the https protocol is used for connection */function setCookie (cookieName, cookieValue, seconds, path, domain, secure) {var expires = new Date (); var seconds = arguments [2]? Arguments [2]: 3600; expires. setTime (expires. getTime () + seconds * 1000); document. cookie = escape (cookieName) + '=' + escape (cookieValue) + (expires? '; Expires =' + expires. toGMTString (): '') + (path? '; Path =' + path: '/') + (domain? '; Domain =' + domain: '') + (secure? '; Secure': '');}/** function: required for obtaining Cookie * name, cookie name */function getCookie (name) {var cookie_start = document. cookie. indexOf (name); var cookie_end = document. cookie. indexOf (";", cookie_start); return cookie_start =-1? '': Unescape (document. cookie. substring (cookie_start + name. length + 1, (cookie_end> cookie_start? Cookie_end: document. cookie. length);}/** function: Required to delete or clear a Cookie * name. cookie name */function delCookie (name, value) {var value = arguments [1]? Arguments [1]: null; var exp = new Date (); exp. setTime (exp. getTime ()-1); var val = getCookie (name); if (val! = Null) {document. cookie = name + '=' + value + '; expires =' + exp. toGMTString ();}}
Articles you may be interested in
- Jquery operation cookie, jquery reading cookie, jquery setting cookie, jquery deleting cookie
- MySQL index Operation Command (create index, re-index, query index, delete index) Summary
- Javascript to get the current mouse position (compatible with IE and firefox)
- FckEditor shortcut menu-image deletion function
- Edit the jQuery select drop-down box (add, delete, modify)
- Comparison and Analysis of string encoding functions escape, encodeURI, and encodeURIComponent in javascript
- Compatible with the setting homepage of IE and firefox and the JavaScript code added to favorites
- Js to get the current mouse position, compatible with ie and firefox