風(fēng)之力

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            19 Posts :: 2 Stories :: 18 Comments :: 0 Trackbacks
          cookie,容量4kb,默認(rèn)各種瀏覽器都支持,缺陷就是每次請求,瀏覽器都會把本機(jī)存的cookies發(fā)送到服務(wù)器,無形中浪費(fèi)帶寬。

          userdata,只有ie支持,單個容量64kb,每個域名最多可存10個共計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.asp

          sessionStorage,只有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.aygfsteel.com/emu/archive/2006/10/04/73385.html
          posted on 2006-10-26 20:14 風(fēng)之力 閱讀(1086) 評論(2)  編輯  收藏 所屬分類: javaScript

          Feedback

          # re: cookie、userdata、sessionStorage[轉(zhuǎn)載] 2007-06-26 09:18 ai
          如何設(shè)置讓IE關(guān)閉瀏覽器后數(shù)據(jù)就清除呢?  回復(fù)  更多評論
            

          # re: cookie、userdata、sessionStorage[轉(zhuǎn)載] 2007-06-28 08:34 風(fēng)之力
          @ai
          IE我不清楚了 好像沒這功能
          maxthon有關(guān)閉后清除歷史的功能吧  回復(fù)  更多評論
            


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 龙游县| 肇源县| 栾川县| 长葛市| 常山县| 樟树市| 滦南县| 迁安市| 彭泽县| 焦作市| 祁东县| 边坝县| 葵青区| 阿合奇县| 文化| 海淀区| 岫岩| 琼海市| 和静县| 沅陵县| 武强县| 商洛市| 南昌市| 科尔| 博爱县| 永靖县| 遂溪县| 西乡县| 林州市| 页游| 新宁县| 渭源县| 枣庄市| 永平县| 基隆市| 伊金霍洛旗| 阿坝| 大庆市| 偏关县| 阿鲁科尔沁旗| 罗平县|