DOM Storage鏄湪缃戠粶瀹㈡埛绔瓨鍌ㄩ敭鍊煎鏁版嵁鐨勪竴涓爣鍑嗐€傝繖浣跨绾跨殑缃戠粶搴旂敤鐨勫紑鍙戝彉寰楁洿鍔犲疄闄呭拰绠€鍗曘€傝窡瀹冪湅璧锋潵闈炲父鐩镐技鐨勫彟澶栦竴涓氨鏄痗ookies浜嗭紝浣嗘槸瀹冨湪鏌愪簺鏂归潰姣攃ookies鏈夊緢澶х殑浼樺娍锛?/p>
聽
(1)聽 鏇村ぇ鐨勫瓨鍌ㄧ┖闂淬€俢ookies鐨勫ぇ灏忓ぇ绾﹂檺鍒跺湪4KB宸﹀彸锛岃€孌OM Storage鍒欏湪10MB宸﹀彸锛屽疄鐢ㄦ€уぇ澶ф彁楂樸€傝兘澶熺湡姝g殑鎸佷箙鍖栧埌鏈湴銆?/p>
(2)聽 cookies骞舵病鏈夋彁渚涙案涔呮寔涔呭寲鍒版湰鍦扮殑鏂规硶锛屽畠鎬绘槸浼氳繃鏈燂紝鑰孌OM Storage鍒欐病鏈夎繖涓棶棰樸€傛晥鐜囨洿楂樸€?/p>
(3)聽 cookies鏄渶瑕佸彂鍥炴湇鍔″櫒绔殑锛岃€孌OM Storage鍒欎笉浼氥€?/p>
(4)聽 鎺ュ彛鏇村姞鏍囧噯锛屼娇鐢ㄦ洿鍔犵畝鍗曘€傜浉淇ookie鍦╦avascript涓殑鎿嶄綔鏈夊楹荤儲澶у閮芥槸闈炲父娓呮鐨勶紝鑰孌OM Storage鍒欓渶璺焜son涓€鏍锋搷浣滃嵆鍙€?/p>
聽
褰撶劧瀹冨悓鏍蜂篃鏈変竴浜涚己鐐癸紝姣斿瀹夊叏鍜岄殣绉佹柟闈㈠彲鑳芥帶鍒剁殑涓嶆槸閭d箞濂斤紝瀹冪殑瀛樺偍鏄槑鏂囩殑骞舵湭缁忚繃鍔犲瘑锛屽彲浠ユ瘮杈冨鏄撶殑鑾峰彇瀛樺偍鐨勪俊鎭€?/p>
聽
聽聽聽聽聽聽 鏃犺濡備綍锛孌OM Storage鎵€鍏锋湁鐨勭壒鎬ч兘鏄浜哄崄鍒嗘尟濂嬬殑銆備絾鏄紙鎬讳細鏈変絾鏄級锛岃櫧鐒剁洰鍓嶇殑鍚勪釜娴忚鍣ㄧ殑鏂扮増鏈兘鏀寔杩欎竴鐗规€э紝IE6鍜孖E7浠嶇劧涓嶆敮鎸侊紝IE8宸叉敮鎸併€備笉瑕佹伯涓э紝铏界劧IE6鏄釜璁╀汉铔嬬柤鐨勬祻瑙堝櫒锛屼絾鏄€冭檻涓€涓嬪畠鐨勫嚭鐢熸棩鏈熶綘浼氳寰楀畠宸茬粡寰堢濂囦簡銆侷E6涓彲浠ラ€氳繃userData Behavior鏉ュ疄鐜扮被浼肩殑鑳藉姏銆傚綋鐒堕檺鍒跺浜嗕竴浜涳紝鍥犵壒缃戠殑瀛樺偍绌洪棿鍙湁1MB宸﹀彸锛屼笉杩囨湁鎬绘瘮娌℃湁寮恒€?/p>
聽
涓嬮潰浠嬬粛涓€涓婦OM Storage鐨勪竴浜涚啛鎮夊拰鏂规硶銆侱OM Storage鍖呮嫭涓ょ瀵硅薄锛歴essionStorage鍜宭ocalStorage锛?/p>
聽
sessionStorage瀵硅薄锛氬湪涓€涓〉闈細璇濇湁鏁堟湡鍐呭彲浠ヤ娇鐢ㄧ殑瀛樺偍瀵硅薄銆?/p>
聽
localStorage瀵硅薄锛氬彲浠ヨ法澶氫釜绐楀彛锛屽涓細璇濓紝涔熷彲浠ヤ负鍩熸彁渚涙寔涔呮€у瓨鍌ㄣ€?/p>
姣?涓煙鍜屽瓙鍩熼兘鍏锋湁鑷繁鍗曠嫭鐨勬湰鍦板瓨鍌ㄥ尯鍩熴€?鍩熷彲浠ヨ闂瓙鍩熺殑瀛樺偍鍖哄煙锛岃€屽瓙鍩熶篃鍙互璁块棶鐖跺煙鐨勫瓨鍌ㄥ尯鍩熴€?渚嬪锛?localStorage['example.com'] 鍙敱 example.com 鍙婂叾浠讳綍瀛愬煙璁块棶銆?瀛愬煙
localStorage['www.example.com'] 鍙敱 example.com 璁块棶锛屼絾涓嶈兘鐢卞叾浠栧瓙鍩熻闂紝濡?mail.example.com銆?/p>
聽
Storage瀵硅薄鐨勫睘鎬у拰鏂规硶锛?/p>
clear 鏂规硶锛氫粠 DOM 瀛樺偍鍖哄煙涓Щ闄ゆ墍鏈夐敭/鍊煎銆?/p>
constructor 灞炴€э細杩斿洖瀵瑰璞$殑鏋勯€犲嚱鏁扮殑寮曠敤銆?/p>
getItem 鏂规硶锛氭绱笌 DOM 瀛樺偍閿叧鑱旂殑褰撳墠鍊笺€?/p>
key 鏂规硶锛氭绱㈤泦鍚堜腑鎸囧畾绱㈠紩澶勭殑閿€?/p>
length 灞炴€э細妫€绱㈤敭/鍊煎垪琛ㄧ殑闀垮害銆?/p>
remainingSpace 灞炴€э細妫€绱㈠彲鐢ㄤ簬瀛樺偍瀵硅薄鐨勫墿浣欏唴瀛樼┖闂?/p>
removeItem 鏂规硶锛氫粠 DOM 瀛樺偍闆嗗悎涓垹闄ら敭/鍊煎銆?/p>
setItem 鏂规硶锛氳缃敭/鍊煎銆?/p>
聽
IE6鍜孖E7涓嬫槸閫氳繃userData Behavior鏄疄鐜扮殑锛屽畠闇€瑕佺敤鍒癰ehavior杩欎釜IE涓嬬鏈夌殑灞炴€с€傚畠鏈変竴涓嬪睘鎬у拰鏂规硶锛?/p>
聽
expires 灞炴€?/p>
XMLDocument 灞炴€?/p>
getAttribute 鏂规硶
load 鏂规硶
removeAttribute 鏂规硶
save 鏂规硶
setAttribute 鏂规硶
聽
鎵嬪唽浠嬬粛鐨勫樊涓嶅浜嗭紝鍏夋槸缃楀垪杩欎簺鎵嬪唽娌″暐鐢ㄥ锛屼负浜嗘柟渚夸娇鐢ㄦ垜杩欓噷灏佽浜嗕竴涓璞$敤浜巐ocalStorage鐨勫瓨鍙栵紝璁╄繖涓璞″湪淇濇寔鍏煎鐨勫悓鏃朵娇鐢ㄨ捣鏉ヤ篃鑳藉鏇村姞鏂逛究銆?/p>
搴熻瘽涓嶅璇达紝涓?span style="background-color: #ff0000;">浠g爜(?????????????)锛?/p>
聽
(function(w){ var isSupportLocalStorage =!!window.localStroage, isSupportBehavior = false; if(!isSupportLocalStorage){ var dataObj = document.createElement('input'); dataObj.type='hidden'; document.body.appendChild(dataObj); isSupportBehavior =!! dataObj.addBehavior; isSupportBehavior && dataObj.addBehavior('#default#userData'); } var configs ={ storeName:'editorContent'}; w.storage={ retrieve:function(name){ if(!isSupportLocalStorage && isSupportBehavior){ dataObj.load(configs.storeName); return dataObj.getAttribute(name); }else{ return w.localStorage.getItem(name); } return null; }, save:function(name, value){ if(!isSupportLocalStorage && isSupportBehavior){ dataObj.setAttribute(name, value); dataObj.save(configs.storeName); return true; }else{ w.localStorage.setItem(name, value); return true; } return false; } }; })(window);