There are many ways to set up a cookie in JS.
The first type: (This is the Code of the website)
<script>//Set Cookiesfunction Setcookie (CNAME, cvalue, exdays) {varD =NewDate (); D.settime (D.gettime ()+ (exdays* -* -* -* +)); varexpires ="expires="+d.toutcstring (); Document.cookie= CNAME +"="+ Cvalue +"; "+expires;}//Get Cookiesfunction GetCookie (CNAME) {varName = CNAME +"="; varCA = Document.cookie.split (';'); for(varI=0; i<ca.length; i++) { varc =Ca[i]; while(C.charat (0)==' ') C = c.substring (1); if(C.indexof (name)! =-1)returnc.substring (Name.length, c.length); } return "";}//Clearing Cookiesfunction ClearCookie (name) {Setcookie (name,"", -1); } function Checkcookie () {varuser = GetCookie ("username"); if(User! ="") {alert ("Welcome again"+user); } Else{User= Prompt ("Please enter your name:",""); if(User! =""&& User! =NULL) {Setcookie ("username", User,365); }}}checkcookie (); </script>
The second type:
<script>//JS operation cookies Method!//Write Cookiesfunction Setcookie (c_name, value, expiredays) {varExdate=NewDate (); Exdate.setdate (Exdate.getdate ()+expiredays); Document.cookie=c_name+"="+ Escape (value) + ((expiredays==NULL) ?"":"; expires="+exdate.togmtstring ()); } //Read Cookiesfunction GetCookie (name) {vararr,reg=NewREGEXP ("(^| )"+name+"=([^;] *)(;|$)"); if(arr=Document.cookie.match (reg))return(arr[2]); Else return NULL;}//Delete Cookiesfunction Delcookie (name) {varExp =NewDate (); Exp.settime (Exp.gettime ()-1); varCval=GetCookie (name); if(cval!=NULL) Document.cookie= name +"="+cval+"; expires="+exp.togmtstring ();}//using the exampleSetcookie ('username','Darren', -) alert (GetCookie ("username"));</script>
JS set cookies, delete cookies