1. 对比cookie
// cookie array function getCookieArrayByStr(str)
{
var cookies = str.split("; ");
var cookieObj = {}
for (var i=0; i<cookies.length; i++)
{
var line = cookies[i];
var pos = line.indexOf("=");
var key = line.substr(0, pos);
var val = line.substr(pos+1);
cookieObj[key] = val;
}
return cookieObj;
} function getCookieArray()
{
return getCookieArrayByStr(document.cookie);
} function compareCookie(strOldCookie)
{
var objOld = getCookieArrayByStr(strOldCookie);
var objNew = getCookieArray(); var oldOnly = {};
var newOnly = {};
var diff = {}; for (var key1 in objOld)
{
var val1 = objOld[key1];
var val2 = objNew[key1];
if (typeof(val2) == "undefined")
{
oldOnly[key1] = val1;
}
else
{
if (val1 != val2)
{
diff[key1] = {oldVal: val1, newVal: val2};
}
}
} for (var key2 in objNew)
{
var val1 = objOld[key2];
var val2 = objNew[key2];
if (typeof(val1) == "undefined")
{
newOnly[key2] = val2;
}
} var retObj = {};
retObj.__OLDO = oldOnly;
retObj.__NEWO = newOnly;
retObj.__DIFF = diff; return retObj;
} var strOldCookie = "cookieUserId=1386816500920952; cuid=1386816500920605" var ret = compareCookie(strOldCookie);