Jquery implements cookie login to remember the username and password problem. You only need to write the corresponding js method on the page without any processing at the background, and you will be able to remember the username and password at the next login.
First, we will introduce how jquery reads cookies.
Example $. cookie (the _ cookie, the _ value ');
Set the cookie value
Example $. cookie (the _ cookie, the _ value, {expires: 7, path: '/', domain: 'jquery. com ', secure: true });
Create a cookie, including the Domain Name of the validity period.
Example $. cookie (the _ cookie, the _ value ');
Create cookie
Example $. cookie (the _ cookie, null );
Delete a cookie
View A dz cookie Traversal method
Processing of split arrays
Function getcookie (name ){
Var cookie_start = document. cookie. indexof (name );
Var cookie_end = document. cookie. indexof (";", cookie_start );
Return cookie_start =-1? '': Unescape (document. cookie. substring (cookie_start + name. length + 1, (cookie_end> cookie_start? Cookie_end: document. cookie. length )));
}
Function setcookie (cookiename, cookievalue, seconds, path, domain, secure ){
Var expires = new date ();
Expires. settime (expires. gettime () + seconds );
Document. cookie = escape (cookiename) + '=' + escape (cookievalue)
+ (Expires? '; Expires =' + expires. togmtstring ():'')
+ (Path? '; Path =' + path :'/')
+ (Domain? '; Domain =' + domain :'')
+ (Secure? '; Secure ':'');
}
Okay, there's a lot to talk about. Now let's get in.
Public static void showcookies ()
{
Int16 I;
Httpcookiecollection cookies = system. web. httpcontext. current. request. cookies;
For (I = 0; I <cookies. count; I ++)
{
Httpcookie cookie = cookies. get (I );
System. web. httpcontext. current. response. write ("cookie name:" + cookie. name + "<br/> ");
System. web. httpcontext. current. response. write ("value =:" + cookie. value + "<br/> ");
System. web. httpcontext. current. response. write ("expires Duration:" + cookie. expires. tostring () + "<br/> ");
System. web. httpcontext. current. response. write ("// System. web. httpcontext. current. response. write ("domain:" + cookie. domain + "<br/> ");
// System. web. httpcontext. current. response. write ("path:" + cookie. path + "<br/> ");
// System. web. httpcontext. current. response. write ("secure confidential:" + cookie. secure + "<br/> ");
}
System. web. httpcontext. current. response. write ("Total" + cookies. count + "cookies <br/> ");
}
Public static void deleteallcookies ()
{
Int16 I;
Httpcookiecollection cookies = system. web. httpcontext. current. request. cookies;
For (I = 0; I <cookies. count; I ++)
{
Httpcookie cookie = cookies. get (I );
Cookie. value = "";
Cookie. expires = datetime. now. adddays (-365 );
System. web. httpcontext. current. response. cookies. set (cookie );
}
System. web. httpcontext. current. response. write ("Total" + cookies. count + "cookies deleted <br/> ");
/* Cookies. clear ();*/
}
Public static void clearallcookies ()
{
Int16 I;
Httpcookiecollection cookies = system. web. httpcontext. current. request. cookies;
For (I = 0; I <cookies. count; I ++)
{
Httpcookie cookie = cookies. get (I );
Cookie. value = "";
System. web. httpcontext. current. response. cookies. set (cookie );
}
System. web. httpcontext. current. response. write ("Total" + cookies. count + "cookies cleared <br/> ");
}
Jquery cookie plugin
Http://plugins.jquery.com/project/cookie