First, two methods are provided. One is to store cookies and the other is to retrieve cookies. This method can be used to store cookies compatible with Chinese characters.
Function Get_cookie (name ){ VaR Start = Document. Cookie. indexof (name + "=" ); VaR Len = start + name. Length + 1 ; If ((! Start) & (name! = Document. Cookie. substring (0, name. Length ))) Return Null ; If (START =-1) Return Null ; VaR End = Document. Cookie. indexof (";" , Len ); If (END =-1) End = Document. Cookie. length; Return Decodeuri (document. Cookie. substring (Len, end ));} Function Set_cookie (name, value, expires, path, domain, secure) {expires = Expires * 60*60*24*1000 ; VaR Today =New Date (); VaR Expires_date = New Date (today. gettime () + (Expires )); VaR Cookiestring = Name + "=" + decodeuricomponent (value) /* * Encodeuricomponent (value) seems to be OK * */ + (Expires) ? "; Expires =" + expires_date.togmtstring (): "") + (PATH) ? "; Path =" + path: "") +(Domain) ? "; Domain =" + domain: "") + (Secure) ? "; Secure ":"" ); Document. Cookie = Cookiestring ;}
When you want to store cookies, call the set_cookie function,
Set_cookie ("dynewform_name", zhuname, 36500 );
In this example, "dynewform_name" is the name of the Set cookie, zhuname is the value of the cookie name, And 36500 is the storage cycle, which is sufficient for general cookie operations.
Other input parameters are not explained,
When the stored cookie is called, The get_cookie function is called.
VaRNameone = get_cookie ("dynewform_name ");
Alert (nameone) // ==> zhuname
In this way, the cookie value dynewform_name is obtained. Sometimes, if the value is Chinese, decodeuricomponent is required.
That is:
VaR new_nameone = decodeuricomponent (nameone );
Write is not necessarily correct, but it is basically available ~