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.