(1) the current page is not set with the same name; ()
(2) The cookie with the same name has been set on the current page. The main test is Code As follows:
// A super-long string exceeding 4 K
VaR longstring = 'dfsafdsafdfsafdsafdfsafdsafdsafdfsafdfsafdfs
Afdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfs
Afdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdsaf
Dfsafdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdf
Safdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdsafdfsafdfsafdsafdfs
Afdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdsafdfsafdfsafdsafdsafdfsaf
Dsafdfsafdsafdfsafdsafdfsafdsafdsafdfsafdsafdfsafdfsafdsafdsafdfsafdsafd
Fsafdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdsafdfsafdfsafdsafdsafdfsa
Fdsafdfsafdsafdfsafdsafdfsafdsafdsafdfsafdsafdfsafdfsafdsafdsafdfsafdsafdf
Bytes
Bytes
Bytes
Bytes
Bytes
Dfsafdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdsafdfsafdfsaf
Dsafdfsa
Fdsafdfsafdsafdfsafdsafdfsafdsafdsafdfsafdsafdfsafdfsafdsafdsafdfsa
Fdsafdfsafdsafdfsafdsafdfsafdsafdsafdfsafdsafdfsafdfsafdsafdsafdfsafdsaf
Bytes
;
// 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 containsArticleTwo situations mentioned at the beginning:
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;
browser version |
output result |
IE6 |
null |
IE7 |
null |
IE8 |
null |
firefox |
null |
chrome |
null |
opera |
null |
Conclusion: Writing strings larger than 4 kb in browsers of the above versions (of course, different browsers may have different situations, some are 4095 bytes, some are 4096 bytes, the write truncation cannot be performed. (2) The cookie with the same name has been set on the current page;
browser version |
output result |
IE6 |
null |
IE7 |
null |
IE8 |
set cookie |
firefox |
set cookie |
chrome |
set cookie |
opera |
set cookie |
Conclusion: If a value named 'test' already exists in browsers of the above versions, the data written exceeds 4 kb (of course, the situation may vary with browsers, some are 4095 bytes, and some are 4096 bytes) string: 1. in IE6 and IE7, when a super-long string cannot be written, the cookie value with the original key 'test' is 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.
(1) the current page is not set with the same name; ()
(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 = 'dfsafdsafdfsafdsafdfsafdsafdsafdfsafdfsafdfs
Afdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfs
Afdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdsaf
Dfsafdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdf
Safdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdsafdfsafdfsafdsafdfs
Afdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdsafdfsafdfsafdsafdsafdfsaf
Dsafdfsafdsafdfsafdsafdfsafdsafdsafdfsafdsafdfsafdfsafdsafdsafdfsafdsafd
Fsafdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdsafdfsafdfsafdsafdsafdfsa
Fdsafdfsafdsafdfsafdsafdfsafdsafdsafdfsafdsafdfsafdfsafdsafdsafdfsafdsafdf
Bytes
Bytes
Bytes
Bytes
Bytes
Dfsafdsafdfsafdsafdfsafdsafdfsafdfsafdsafdfsafdsafdfsafdfsaf
Dsafdfsa
Fdsafdfsafdsafdfsafdsafdfsafdsafdsafdfsafdsafdfsafdfsafdsafdsafdfsa
Fdsafdfsafdsafdfsafdsafdfsafdsafdsafdfsafdsafdfsafdfsafdsafdsafdfsafdsaf
Bytes
;
// 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;
browser version |
output result |
IE6 |
null |
IE7 |
null |
IE8 |
null |
firefox |
null |
chrome |
null |
opera |
null |
Conclusion: Writing strings larger than 4 kb in browsers of the above versions (of course, different browsers may have different situations, some are 4095 bytes, some are 4096 bytes, the write truncation cannot be performed. (2) The cookie with the same name has been set on the current page;
browser version |
output result |
IE6 |
null |
IE7 |
null |
IE8 |
set cookie |
firefox |
set cookie |
chrome |
set cookie |
opera |
set cookie |
Conclusion: If a value named 'test' already exists in browsers of the above versions, the data written exceeds 4 kb (of course, the situation may vary with browsers, some are 4095 bytes, and some are 4096 bytes) string: 1. in IE6 and IE7, when a super-long string cannot be written, the cookie value with the original key 'test' is 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.