下面是其它网友文章:
js 保存大量数据.
IE系列存储到电脑上,直到删除文件.
FF关闭则删除
<script> <BR>//userData类 <BR>var RuserData={ <BR>o:null, <BR>timeExpires:7, <BR>browser:'', <BR>//初始化userdata <BR>init:function() <BR>{ <BR>if(this.browser != '') <BR>return true; <BR>if(window.ActiveXObject)//for IE { <BR>try{ <BR>this.o=document.createElement("input"); <BR>this.o.id="Ruserdata"; <BR>this.o.type="hidden"; <BR>this.o.style.behavior="url(#default#userData)"; <BR>this.browser='ie'; <BR>document.body.appendChild(this.o); <BR>return true; <BR>}catch(e){return false;} <BR>}else if(window.sessionStorage)//FF 2.0+*/ <BR>{ <BR>try{ <BR>this.o=window.sessionStorage; <BR>this.browser='ff'; <BR>return true; <BR>}catch(e){return false;} <BR>} <BR>return false; <BR>}, <BR>setVal:function(key,val,timeout/*正定义超时时间,为空用默认值*/){ <BR>this.init(); <BR>if(this.browser == 'ie'){ <BR>try{ <BR>this.o.load(key); <BR>this.o.expires=typeof timeout == 'undefined' ? this.getTimeLimit(this.timeExpires) : this.getTimeLimit(timeout); <BR>this.o.setAttribute('value',val); <BR>this.o.save(key); <BR>return true; <BR>}catch(e){return false} <BR>}else if(this.browser == 'ff'){ <BR>try{this.o.setItem(key,val);return true;} <BR>catch(e){return false} <BR>} <BR>}, <BR>getVal:function(key){ <BR>this.init(); <BR>if(this.browser == 'ie'){ <BR>try{ <BR>this.o.load(key); <BR>return this.o.getAttribute('value'); <BR>}catch(e){return false;} <BR>}else if(this.browser == 'ff'){ <BR>try{return this.o.getItem(key);} <BR>catch(e){return false} <BR>} <BR>}, <BR>delVal:function(key){ <BR>this.init(); <BR>if(this.browser == 'ie'){ <BR>try{ <BR>this.o.load(key); <BR>this.o.expires=new Date(315532799000).toUTCString(); <BR>this.o.save(key); <BR>return true; <BR>} <BR>catch(e){return false;} <BR>}else if(this.browser == 'ff'){ <BR>try{this.o.removeItem(key);return true;} <BR>catch(e){return false} <BR>} <BR>}, <BR>getTimeLimit:function(days/*设置超时天数*/){ <BR>var d=new Date(); <BR>d.setDate(d.getDate() + days); <BR>return d.toUTCString(); <BR>} <BR>}; <BR>window.onload=function(){ <BR>//alert(RuserData.delVal('renchao')); <BR>//alert(RuserData.setVal('renchao','脚本之家www.jb51.net')); <BR>alert(RuserData.getVal('renchao')); <BR>} <BR></script>
使用方法:
window.onload=function(){ //alert(RuserData.delVal('renchao')); //alert(RuserData.setVal('renchao','脚本之家www.jb51.net')); alert(RuserData.getVal('renchao')); }
Stellungnahme: Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn