Production process I will not say, the program will be taken up under
Definefunction(){ if(' Localstorage 'inchWindowreturn; functionStorage () { This. Box = Document.body | | Document.getelementbytagname (' head ') [0] | |document.documentelement; This. Name = ' Localstorage ' This. data = Document.createelement ( This. Name); This. Data.addbehavior ("#default #userdata"); This. Box.appendchild ( This. Data); This. Map = []; This. length = This. Length (); } Storage.prototype.setItem=function(name,val) {if(name== ' Localstorage-map '){ Throw NewError ("This was localstorage in key [Localstorage-map] not use!") return ; } if( This. map.length==0){ This. Data.load (' Localstorage-map '); vardata = This. Data.getattribute (' Localstorage-map '); if(data!=NULL){ This. Map = Data.split (', '); } } varFlag =true; for(varIinch This. Map) { if( This. map[i] = =name) {Flag=false; } } if(flag) { This. Map.push (name)} This. Data.setattribute (Name,val); varDate =NewDate (); Date.setdate (Date.getdate ()+700); This. Data.expires =date.toutcstring (); This. Data.save (name); This. Data.setattribute (' Localstorage-map ', This. map); This. Data.save (' Localstorage-map '); } Storage.prototype.getItem=function(name) {if(name = = ' Localstorage-map ')){ Throw NewError ("This was localstorage in key [Localstorage-map] not use!"); return; } This. Data.load (name); return This. Data.getattribute (name); }; Storage.prototype.length=function(){ if( This. map.length==0){ This. Data.load (' Localstorage-map '); vardata = This. Data.getattribute (' Localstorage-map '); if(data!=NULL){ This. Map = Data.split (', '); } } for(vari = This. map.length-1; I >= 0; i--) {alert ( This. GetItem ( This. Map[i])) if( This. GetItem ( This. map[i]) ==undefined | | This. GetItem ( This. map[i]) = = ""){ This. Map.splice (i,1); } } return This. Map.length; }; Storage.prototype.removeItem=function(name) {if(typeofname== "Undefined" | | name== "")return; if( This. map.length==0){ if( This. GetItem (' Localstorage-map ')! =NULL){ This. Map = This. GetItem (' Localstorage-map '). Split (', '); } } for(varIinch This. Map) { if( This. map[i] = =name) { This. Map.splice (i,1); } } This. Data.load (name); This. Data.setattribute (name,undefined); This. Data.save (name); return true; }, Storage.prototype.clear=function(){ if( This. map.length==0){ if( This. GetItem (' Localstorage-map ')! =NULL){ This. Map = This. GetItem (' Localstorage-map '). Split (', '); } } for(varIinch This. Map) { This. RemoveItem ( This. Map[i]); }} window.localstorage=NewStorage ();});
Calling programs
Localstorage.setitem (' value ', ' {askdjf:ddd} ') localstorage.setitem (' name ', ' {ddddddd:ddd} ') Alert ( localstorage.getitem (' value ')) alert ( localstorage.getitem (' name ')) alert ( Localstorage.removeitem (' name ')) alert (localstorage.length);
I was just a simple test to be able, do not know where there are problems, looking at the twos!!!!!
Localstorage compatible IE6/7 with Addbehavior implementation