改版了網(wǎng)上的一個js操作userdata
更新時間:2007年04月27日 00:00:00 作者:
改版了網(wǎng)上的一個js操作userdata,并根據(jù)其它網(wǎng)友的文章結(jié)合了下。希望對需要的朋友有所幫助。
復制代碼 代碼如下:
<input type=text id=a><button onclick="Session.save('a',a.value);"><button onclick="alert(Session.load('a'))">
<body>
<SCRIPT LANGUAGE="JavaScript">
<!--
var Session={
isinit:false,
init:function(){
SessionObj = document.createElement('input');
SessionObj.type = "hidden";
SessionObj.id = "Sessionid";
SessionObj.style.behavior = "url('#default#userData')"
document.body.appendChild(SessionObj);
this.isinit=true;
},
save:function(sessionName,value){
this.isinit?'':this.init();
if (sessionName != null && sessionName != ""){
SessionObj.setAttribute(sessionName,value)
SessionObj.save("s")
}
},
load:function(sessionName){
this.isinit?'':this.init();
if (sessionName != null && sessionName != ""){
SessionObj.load("s");
return SessionObj.getAttribute(sessionName);
}
}
}
//-->
</SCRIPT>
下面是其它網(wǎng)友文章:
js 保存大量數(shù)據(jù).
IE系列存儲到電腦上,直到刪除文件.
FF關(guān)閉則刪除
復制代碼 代碼如下:
<script>
//userData類
var RuserData={
o:null,
timeExpires:7,
browser:'',
//初始化userdata
init:function()
{
if(this.browser != '')
return true;
if(window.ActiveXObject)//for IE {
try{
this.o=document.createElement("input");
this.o.id="Ruserdata";
this.o.type="hidden";
this.o.style.behavior="url(#default#userData)";
this.browser='ie';
document.body.appendChild(this.o);
return true;
}catch(e){return false;}
}else if(window.sessionStorage)//FF 2.0+*/
{
try{
this.o=window.sessionStorage;
this.browser='ff';
return true;
}catch(e){return false;}
}
return false;
},
setVal:function(key,val,timeout/*正定義超時時間,為空用默認值*/){
this.init();
if(this.browser == 'ie'){
try{
this.o.load(key);
this.o.expires=typeof timeout == 'undefined' ? this.getTimeLimit(this.timeExpires) : this.getTimeLimit(timeout);
this.o.setAttribute('value',val);
this.o.save(key);
return true;
}catch(e){return false}
}else if(this.browser == 'ff'){
try{this.o.setItem(key,val);return true;}
catch(e){return false}
}
},
getVal:function(key){
this.init();
if(this.browser == 'ie'){
try{
this.o.load(key);
return this.o.getAttribute('value');
}catch(e){return false;}
}else if(this.browser == 'ff'){
try{return this.o.getItem(key);}
catch(e){return false}
}
},
delVal:function(key){
this.init();
if(this.browser == 'ie'){
try{
this.o.load(key);
this.o.expires=new Date(315532799000).toUTCString();
this.o.save(key);
return true;
}
catch(e){return false;}
}else if(this.browser == 'ff'){
try{this.o.removeItem(key);return true;}
catch(e){return false}
}
},
getTimeLimit:function(days/*設(shè)置超時天數(shù)*/){
var d=new Date();
d.setDate(d.getDate() + days);
return d.toUTCString();
}
};
window.onload=function(){
//alert(RuserData.delVal('renchao'));
//alert(RuserData.setVal('renchao','腳本之家www.dbjr.com.cn'));
alert(RuserData.getVal('renchao'));
}
</script>
使用方法:
復制代碼 代碼如下:
window.onload=function(){
//alert(RuserData.delVal('renchao'));
//alert(RuserData.setVal('renchao','腳本之家www.dbjr.com.cn'));
alert(RuserData.getVal('renchao'));
}
相關(guān)文章
JavaScript對JSON數(shù)組簡單排序操作示例
這篇文章主要介紹了JavaScript對JSON數(shù)組簡單排序操作,結(jié)合實例形式分析了javascript使用sort()方法針對json數(shù)組元素排序的相關(guān)操作技巧與注意事項,需要的朋友可以參考下2019-01-01基于BootStrap Metronic開發(fā)框架經(jīng)驗小結(jié)【五】Bootstrap File Input文件上傳插件的用法
本文主要基于我自己的框架代碼案例,介紹其中文件上傳插件File Input的使用,非常具有參考借鑒價值,感興趣的朋友一起學習吧2016-05-05JavaScritp添加url參數(shù)并將參數(shù)加入到url中及更改url參數(shù)的方法
這篇文章給大家介紹javascript添加url參數(shù)方法,將參數(shù)加入到url中,涉及到url添加參數(shù)的相關(guān)知識,關(guān)于js添加url參數(shù)感興趣的朋友可以參考下本篇文章2015-10-10js使用split函數(shù)按照多個字符對字符串進行分割的方法
這篇文章主要介紹了js使用split函數(shù)按照多個字符對字符串進行分割的方法,實例分析了split函數(shù)的使用技巧,非常具有實用價值,需要的朋友可以參考下2015-03-03JavaScript常用進制轉(zhuǎn)換及位運算實例解析
這篇文章主要介紹了JavaScript常用進制轉(zhuǎn)換及位運算實例解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-10-10js傳中文參數(shù)controller里獲取參數(shù)亂碼問題解決方法
js傳中文參數(shù),在controller里獲取參數(shù)亂碼的問題在本文有個不錯的解決方法,感興趣的朋友可以參考下2014-01-01bootstrap模態(tài)框關(guān)閉后清除模態(tài)框的數(shù)據(jù)方法
今天小編就為大家分享一篇bootstrap模態(tài)框關(guān)閉后清除模態(tài)框的數(shù)據(jù)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08