風(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支持,單個(gè)容量64kb,每個(gè)域名最多可存10個(gè)共計(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.asp

          sessionStorage,只有firefox2支持的臨時(shí)數(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)航:
           
          主站蜘蛛池模板: 炎陵县| 东海县| 湘潭县| 息烽县| 营口市| 浙江省| 天水市| 荥经县| 赫章县| 福安市| 开原市| 玉田县| 营山县| 阜南县| 二连浩特市| 铁岭县| 托里县| 道孚县| 阳原县| 萨迦县| 兴化市| 正阳县| 高邑县| 嘉兴市| 三台县| 鹤岗市| 沈丘县| 皋兰县| 湟中县| 鄂尔多斯市| 郎溪县| 阜南县| 丰县| 治县。| 河池市| 宜春市| 四平市| 嫩江县| 通道| 广宁县| 新化县|