Cookies on the Internet

Source: Internet
Author: User
Tags set cookie

The method for saving information to the user's client hard disk in Javascript is relatively limited. This is due to security considerations. However, the hard disk write restrictions greatly reduce the Javascript functionality. In this case, the cookie is generated-a restricted Method for writing data to the hard disk.

Cookie restrictions:
These restrictions include. Browser Cookies cannot exceed 300, and each cookie cannot exceed 4 kb. Therefore, the total cookie file size is limited to bytes kb. Each site has no more than 20 cookies.

Cookie storage location:
The netscape4.x browser places the cookie in "E:/program files/Netscape/users/chendian/cookies.txt" where "E:/Program Files" is the location where your browser is installed, "chendian" is your user name.
In IE, cookies are placed in F:/Windows/profiles/C/cookies/c@www_glisp_com(52.16.txt, where "F:/Windows" is the location where windows is installed, c In "profiles/C" is the user name when you log on to Windows.
Of course, you can delete any cookies you do not want to retain by editing the above files.
Here is an example of reading and writing cookies. You can copy them and use them directly on your webpage.

cookie read/write method:
1. Write. You only need a javascript statement to set the cookie, for example:
document. cookie = "CHD = OK";
in this example, the name of the cookie variable you want to set is "OK.
2. Read.
function getcookieval (offset)
{< br> var endstr = document. cookie. indexof (";", offset);
If (endstr =-1)
endstr = document. cookie. length;
return Unescape (document. cookie. substring (offset, endstr);
}< br> function getcookie (name)
{< br> var Arg = Name + "= ";
var Alen = Arg. length;
var clen = document. cookie. length;
var I = 0;
while (I {< br> var J = I + Alen;
If (document. cookie. substring (I, j) = Arg)
return getcookieval (j);
I = document. cookie. indexof ("", I) + 1;
if (I = 0)
break;
}< br> return NULL;
}< br> alert ("coke CHD =" + getcookie ('cct');
Use getcookie ("Cookie variable name ") you can read the previously set cookie.

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.