下面是其它网友文章:
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')); }
Statement: The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn