A javascript cookie processing article

Source: Internet
Author: User

VaR sel = new object ();
VaR sel_num = 0;
Function getcookieval (offset ){
VaR endstr = Document. Cookie. indexof (";", offset );
If (endstr =-1) endstr = Document. Cookie. length;
Return Unescape (document. Cookie. substring (offset, endstr ));
}
Function getcookie (name ){
VaR Arg = Name + "= ";
VaR Alen = Arg. length;
VaR clen = Document. Cookie. length;
// Alert (document. Cookie. Length );
VaR I = 0;
While (I <clen ){
VaR J = I + Alen;
If (document. Cookie. substring (I, j) = Arg)
Return getCookieVal (j );
I = document. cookie. indexOf ("", I) + 1;
If (I = 0) break;
}
Return null;
}

Function SetCookie (name, value, expires, path, domain, secure ){
Document. cookie = name + "=" + escape (value) + (expires )? "; Expires =" + expires. toGMTString (): "") + (path )? "; Path =" + path: "") + (domain )? "; Domain =" + domain: "") + (secure )? "; Secure ":"");

Return value;
}

Function DeleteCookie (name ){
If (GetCookie (name )! = Null ){
Setcookie (name, "", null, "/", null );
}
}

Function cookie_content (){
I = 0;
VaR content = "";
For (key in SEL ){
If (I = 0 ){
Content + = Key + "[" + sel [Key] + "]";
}
Else {
Content + = "," + key + "[" + sel [Key] + "]";
} I ++;
}
Return content;
}
Function inni_data (){
Var cookie_sel = new Object ();
Cookie_str = GetCookie ("Member_COOKIE ");
If (cookie_str! = "" & Cookie_str! = Null ){
Cookie_sel = cookie_str.split (',');
For (var k = 0; k <cookie_sel.length; k ++ ){
I = cookie_sel [k]. indexOf ("[");
J = cookie_sel [k]. indexOf ("]");
Sel [cookie_sel [k]. substring (0, I)] = cookie_sel [k]. substring (I + 1, j );
Sel_num ++;
}
Draw ();
}
}

Function addMember (id, nm ){

If (! Sel [id]) {
Sel_num ++; sel [id] = nm;
}
Else
{Sel [id] = nm ;}

SetCookie ("Member_COOKIE", cookie_content (), null, "/", null );
 
}
Function draw (){
Out = '';
For (key in sel ){
$ ("#" + Key). val (sel [key]);

}

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.