Test on the Cookie content length limit in different browsers (New IE9 official version test results)

Source: Internet
Author: User

To meet project requirements, perform a COOKIE content length limit test and make a record for your reference. The test design is as follows:

(1) No Cookie of the same name is set on the current page;

(2) The Cookie with the same name has been set on the current page;

The main test code is as follows:

// A super-long string exceeding 4 K

Var longString = 'zookeeper zookeeper fdfsafd zookeeper fdsafdfs zookeeper please refer to the following link for more information ';


// Write Cookie Function
Function setCookie (name, value)
{
Var Days = 1; // This cookie will be saved for 1 day
Var exp = new Date ();
Exp. setTime (exp. getTime () + Days x 24x60*60*1000 );
Document. cookie = name + "=" + escape (value) + "; expires =" + exp. toGMTString ();
}

Function getCookie (name) // The cookie function.
{
Var arr = document. cookie. match (new RegExp ("(^ |)" + name + "= ([^;] *) (; | $ )"));
If (arr! = Null) return unescape (arr [2]); return null;
}

// Set the Cookie, which contains the two situations mentioned at the beginning of the article:
SetCookie ('test', 'cookie already set ');

// Set the ultra-long Cookie:
SetCookie ('test', longString );

Alert (getCookie ('test '));

The test results are as follows:

(1) No Cookie of the same name is set on the current page;

Conclusion:

In the browsers of the above versions, writing strings larger than 4 kb (of course, different browsers may have different situations, some are 4095 bytes, some are 4096 bytes) will fail to be written,

The write truncation cannot be performed.

(2) The Cookie with the same name has been set on the current page;

Conclusion:

When a value named 'test' already exists in browsers of the above versions, it is written to a string larger than 4 kb (of course, the situation may be different in different browsers, some are 4095 bytes, some are 4096 bytes:

1. in IE6 and IE7, if a super-long string cannot be written, the Cookie value with the original key 'test' will be affected. In the test results, the Cookie value is cleared;

2. In other browsers, the Cookie value of the original same key name is not affected when the ultra-long string cannot be written. The original Cookie value can still be read normally.

For your reference only.

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.