Set Cookies
function Setcookie (cname,cvalue,exdays) {varD =NewDate (); D.settime (D.gettime ()+ (exdays* -* -* -* +)); varexpires ="expires="+d.togmtstring (); Ocument.cookie= CNAME +"="+ Cvalue +"; "+expires;} Get cookiefunction GetCookie (CNAME) {varName = CNAME +"="; varCA = Document.cookie.split (';'); for(varI=0; i<ca.length; i++) { varc =Ca[i].trim (); if(C.indexof (name) = =0)returnc.substring (name.length,c.length); } return "";} Check cookiefunction 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); } }}
Cookie string
The Document.cookie property looks like a normal text string, but it is not.
Even if you write a full cookie string in Document.cookie, the cookie information is displayed as a name/value pair when you re-read the cookie information.
If you set up a new cookie, the old cookie will not be overwritten. The new cookie will be added to Document.cookie, so if you re-read Document.cookie, you will get the data as shown below:
Cookie1=value; Cookie2=value;
Setting up and checking of cookies in JS