1 <HTML>2 <Head>3 <MetaCharSet= "Utf-8">4 <title>Javascript Cookies</title>5 <Scripttype= "Text/javascript">6 functionGetCookie (c_name)7 {8 alert (document.cookie);9 if(Document.cookie.length>0)Ten { One C_start=document.cookie.indexOf (C_name+ "="); A if(C_start!=-1) - { - C_start=C_start+C_name.length+1; the C_end=Document.cookie.indexOf (";", C_start); - if(C_end==-1) C_end=Document.cookie.length - returnunescape (document.cookie.substring (c_start,c_end)); - } + } - return ""; + } A at functionSetcookie (c_name,value,expiredays) - { - varexdate=NewDate (); - exdate.setdate (exdate.getdate ()+expiredays); - Document.cookie=C_name+ "=" +Escape (value)+((Expiredays== NULL) ? "" : "; expires=" +exdate.togmtstring ()); - } in - functionDelcookie (name) to { + varExp= NewDate (); - Exp.settime (Exp.gettime ()- 1); the varCval=GetCookie (name); * if(Cval!= NULL) $ {Panax Notoginseng Document.cookie=name+ "=" +Cval+ "; expires=" +exp.togmtstring (); - } the } + A functionCheckcookie () the { + varusername=GetCookie ('Testjavascriptcookie'); - if(username!= NULL &&username!= "") $ { $ Alert ('Welcome again' +username+ '!'); - } - Else the { - username=Prompt ('Please enter your name:', "");Wuyi if(username!= NULL &&username!= "") the { - Setcookie ('Testjavascriptcookie', username,365); Wu } - } About } $ - </Script> - </Head> - A <BodyOnLoad= "Checkcookie ();"> + </Body> the </HTML>
JavaScript Cookie Manipulation