风之力

BlogJava 首页 新随笔 联系 聚合 管理
  19 Posts :: 2 Stories :: 18 Comments :: 0 Trackbacks
cookie,容量4kb,默认各种浏览器都支持,缺陷就是每次请求,浏览器都会把本机存的cookies发送到服务器,无形中浪费带宽。

userdata,只有ie支持,单个容量64kb,每个域名最多可存10个共计640k数据。默认保存在C:\Documents and Settings\Administrator\UserData\目录下,保存格式为xml。关于userdata更多资料参考http://msdn.microsoft.com/library/default.asp?url=/workshop/author/behaviors/reference/behaviors/userdata.asp

sessionStorage,只有firefox2支持的临时数据保存,容量大小不祥。


以下是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.blogjava.net/emu/archive/2006/10/04/73385.html
posted on 2006-10-26 20:14 风之力 阅读(1045) 评论(2)  编辑  收藏 所属分类: javaScript

Feedback

# re: cookie、userdata、sessionStorage[转载] 2007-06-26 09:18 ai
如何设置让IE关闭浏览器后数据就清除呢?  回复  更多评论
  

# re: cookie、userdata、sessionStorage[转载] 2007-06-28 08:34 风之力
@ai
IE我不清楚了 好像没这功能
maxthon有关闭后清除历史的功能吧  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: