View Single Post
Old 02-12-2012, 09:05 PM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
use userData persistence for up to 640kb of storage. not 5mb, but a lot better than 4-8kb!


use store(st_req_key, str_opt_val) to store things xbrowser using localStorage, globalStorage, userData, or cookies (fallbacks).

Code:
<html><head>   



<script type="text/javascript" src="http://danml.com/mini/"></script>

<script type="text/javascript">

  store("something", "with data");

</script>
</head><body>



<script type="text/javascript">

  alert(store("something"));

</script>

</body></html>


without a lib:
Code:
<html><head>   





<script type="text/javascript">
var store=function(){
function el(tid) {return document.getElementById(tid);}
if(!window.globalStorage && window.localStorage){
	window.globalStorage={};
      globalStorage[document.domain]=window.localStorage;
}//end webkit+ie8  patch
function setCookie(nm, valu) {var e2 = (new Date(2019, 1, 1)).toGMTString();document.cookie = nm + "=" + escape(valu) + "; expires=" + e2;};
function getCookie(k){var d = document.cookie || "";var pairs = d.split(k + "=");if (pairs && pairs[1]) {return unescape(pairs[pairs.length-1].split(";")[0]);}}
if(window.globalStorage){function store(key,val){if(val){globalStorage[document.domain][key]=val;}else{
  try{var tm=globalStorage[document.domain][key];if(tm){tm=tm.toString();}}catch(rr){return"";}return tm;}return;}
}else{
  var store=function (key,val){if(val){setCookie(key,val);}else{return getCookie(key);}}
}
function iestorer(){
 var D=document;if(!D.createStyleSheet||window.localStorage){return;}
  var tCSS=D.createStyleSheet();tCSS.addRule(".userData","behavior:url(#default#userdata)",0);var Static=D.createElement("input");var Q=function(z,x){Static.setAttribute(z,x);};Q("type","hidden");Q("id","EzStatic420");Q("className","userData");document.getElementsByTagName("head")[0].appendChild(Static);var s=el("EzStatic420");function ies(k,v){if(!v){s.load("oXMLStore");var t=s.getAttribute(k);return unescape(t)||"";}else{s.setAttribute(k,escape(String(v)));s.save("oXMLStore");}}
  store=window.store=ies;
};iestorer();
return store;
}());





  store("something", "with data");

</script>
</head><body>



<script type="text/javascript">

  alert(store("something"));

</script>

</body></html>
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 02-12-2012 at 09:19 PM..
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
devnull69 (02-13-2012)