Js operation cookie, js reading cookie, js setting cookie, js deleting cookie Summary

Source: Internet
Author: User
Tags mysql index

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

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.