varCookie =function (name, value, options) {if(typeofValue!=='undefined') {Options= Options | | {}; if(Value = = =NULL) {Value="'; Options=$.extend ({}, Options); Options.expires= -1; } varexpires ="'; if(Options.expires && (typeofOptions.expires = = =' Number'||options.expires.toUTCString)) {vardate; if(typeofOptions.expires = = =' Number') {Date=NewDate (); Date.settime (Date.gettime ()+ (Options.expires * -* -* -* +)); } Else{Date=Options.expires; } Expires='; expires='+date.toutcstring (); } varPath = Options.path?'; path='+ (Options.path):';p ath=/'; varDomain = Options.domain?'; domain='+ (Options.domain):"'; varSecure = options.secure?'; secure':"'; Document.cookie= [Name,'=', encodeURIComponent (value), expires, path, domain, Secure].join ("'); } Else { varCookievalue =NULL; if(Document.cookie && Document.cookie!=="') { varcookies = Document.cookie.split (';'); for(vari =0; i < cookies.length; i++) { varCookie =$.trim (Cookies[i]); if(Cookie.substring (0, Name.length +1) = = = (name +'=') ) {Cookievalue= decodeURIComponent (cookie.substring (Name.length +1)); Break; } } } returnCookievalue; } } varRemovecookie =function (key) {$.cookie (key,"', {expires:-1 }); }
varStorage =function (St, key, value, expires) {if(St = ='L') {St=Window.localstorage; Expires= Expires | | -; } Else{St=Window.sessionstorage; Expires= Expires | |5; } if(typeofValue! ='undefined') { Try { returnSt.setitem (Key, Json.stringify ({data:value, Expires:NewDate (). GetTime () + expires * +* - })); } Catch(e) {}}Else { varresult = Json.parse (St.getitem (key) | |'{}'); if(Result &&NewDate (). GetTime () <result.expires) {returnResult.data; } Else{St.removeitem (key); return NULL; } } }
Encapsulation Cookie Localstorage Sessionstorage