Document.cookie = ' name= ' + ' username '; Document.cookie= ' value= ' + ' value1 '; varCookarr = Document.cookie.replace (/\s/g, ""). Split (';');//Replace all the spaces in the cookie, or there will be a space to make the result impossible to Judge varHavcome =false; for(vari=0;i<cookarr.length;i++){ varstr = cookarr[i].split (' = ')); if(str[0]== ' Dateam ') {Havcome=true; Break}} console.log (Document.cookie); Console.log (Havcome); varDate =NewDate (); varDay =Date.gettime (); Console.log (day); varNewDay =NewDate (day + 7*24*60*60*1000);//set the expiration time, which is set to seven days later; varOldday =NewDate (day-1);//set the deletion time, as long as the expiration time before the set time, you can delete the cookie;Console.log (newday.toutcstring ()); if(!havcome) {Document.cookie= ' Dateam ' + ' = ' + ' haha ' + '; expires= ' +newday.toutcstring (); Alert (' Welcome to your first visit '); } document.cookie= ' Dateam ' + ' = ' + ' haha ' + '; expires= ' +oldday.toutcstring ();//set the expiration time to 1 Ms already in the past, you can delete the Dateamcookie immediately
JS Operation Cookie,getcookie,setcookie, Removecookie