Use of cookies

Source: Internet
Author: User

1 //Cookie Section2 //Set Cookies3 //Note the CNAME incoming string type, such as: Setcookie (' first ');4 functionSetcookie (cname,cvalue,exdays) {5     varD =NewDate ();6D.settime (D.gettime () + (exdays*24*60*60*1000));7     varexpires = "expires=" +d.togmtstring ();8Document.cookie = cname+ "=" +cvalue+ "; "+expires;9 }Ten //Get Cookies One functionGetCookie (CNAME) { A     varName = CNAME + "="; -     varCA = Document.cookie.split ('; ')); -      for(vari=0; i<ca.length; i++) { the         varc =Ca[i].trim (); -         if(C.indexof (name) ==0)returnc.substring (name.length,c.length); -     } -     return""; + } - //Check Cookies + functionCheckcookie () { A     varUser=getcookie ("username"); at     if(user!= ""){ -Alert ("Welcome again" +user); -     } -     Else { -user = prompt ("Please enter your name:", "" "); -         if(user!= "" && user!=NULL){ inSetcookie ("username", user,30); -         } to     } + } - //Delete a single cookie the functionClearCookie (name) { *Setcookie (Name, "",-1); $ }Panax Notoginseng //Delete all Cookies - functionClearallcookie () { the     varKeys=document.cookie.match (/[^ =;] +(?=\=)/g); +     if(keys) { A          for(vari = keys.length; i--;) thedocument.cookie=keys[i]+ ' =0;expires= ' +NewDate (0). toUTCString () +     } -}

Use of 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.