cookie,容量4kb,默認(rèn)各種瀏覽器都支持,缺陷就是每次請求,瀏覽器都會把本機(jī)存的cookies發(fā)送到服務(wù)器,無形中浪費(fèi)帶寬。
userdata,只有ie支持,單個容量64kb,每個域名最多可存10個共計(jì)640k數(shù)據(jù)。默認(rèn)保存在C:\Documents and Settings\Administrator\UserData\目錄下,保存格式為xml。關(guān)于userdata更多資料參考
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/behaviors/reference/behaviors/userdata.aspsessionStorage,只有firefox2支持的臨時數(shù)據(jù)保存,容量大小不祥。
以下是js片段,拿來替代cookies還是蠻爽滴,HOHO。
?1?if(window.ActiveXObject)?{document.documentElement.addBehavior("#default#userdata");}; ?2? ?3???var?Cache?=?{ ?4?????set?:?function(key,?value)?{ ?5???????if(window.ActiveXObject)?{//for?ie5.0+ ?6?????????with(document.documentElement){ ?7???????????try{ ?8?????????????load(key); ?9?????????????setAttribute("js",?value); 10?????????????save(key); 11???????????}catch?(ex){ 12?????????????setAttribute("js",?value); 13?????????????save(key); 14???????????}; 15?????????}; 16???????}else?if(window.sessionStorage)?{//for?firefox2.0+ 17?????????sessionStorage.setItem(key,?value); 18???????}; 19?????}, 20?????get?:?function(key)?{ 21???????if(window.ActiveXObject)?{ 22?????????with(document.documentElement){ 23???????????try{ 24?????????????load(key); 25?????????????return?getAttribute("js"); 26???????????}catch?(ex){ 27?????????????return?null; 28???????????}; 29?????????}; 30???????}else?if(window.sessionStorage)?{ 31?????????return?sessionStorage.getItem(key); 32???????}else{ 33?????????return?null; 34???????}; 35?????}, 36?????remove?:?function(key)?{ 37???????if(window.ActiveXObject)?{ 38?????????with(document.documentElement){ 39???????????try{ 40?????????????load(key); 41?????????????expires?=?new?Date(315532799000).toUTCString(); 42?????????????save(key); 43???????????}catch?(ex){}; 44?????????}; 45???????}else?if(window.sessionStorage)?{ 46?????????sessionStorage.removeItem(key); 47???????}; 48?????} 49???} |
感謝emu的說明
http://www.tkk7.com/emu/archive/2006/10/04/73385.html