这个也是html5中提出来,在浏览器关闭以后,使用globalStorage存储的信息仍能够保留下来,并且存储容量比IE的userdata大得多,一个域下面是5120k。和sessionStorage一样,域中任何一个页面存储的信息都能被所有的页面共享。
作用域
globalStorage['z.baidu.com'] 所有z.baidu.com下面的页面都可以使用这块空间
globalStorage['baidu.com'] 所有baidu.com下面的页面都可以使用这块空间
globalStorage['com']:所有com域名都可以 共享的使用这一块空间
globalStorage[''] :所有页面都可以使用的空间
现在Firefox只支持当前域下的globalStorage存储, 如果使用公用域会导致一个这样一个类似的错误“Security error” code: “1000”。
过期时间
按照HTML5的描述,globalStorage只在安全问题或者当用户要求时才会过期,浏览器应该避免删除那些正在被脚本访问的数据,并且userdata应该是用户可写的。
因此我们的脚本要能够控制过期时间,可以在globalStorage的某个区域存储过期时间,在load的时候判断是否过期,可以在一定程度上解决过期时间的问题。
存储时,同时存储过期时间
以上是我从网上查询到的资料,为了兼容非IE浏览器“userdata”,我改进了之前我自己写的一个
“userdata”(见 UserData使用总结) ,现在是兼容IE和支持globalStorage的浏览器了。
function behaviorUserdata(udObj)
{
var me = this;
if(CMInfo.Bs_Name=='IE') //IE下用userdata实现客户端存储
{
var loaded = ''; //当前已载入的文件名
this.udObj = getObject(udObj);
this.udObj.style.behavior = 'url(#default#userdata)';
this.value = this.udObj.value;
this.inhtml = this.udObj.innerHTML;
//检查文件是否存在,存在est=undefined并返回true否则返回false
this.exist = function(filename){
try{
me.udObj.load(filename);//将文件名为 filename的 XML 载入
me.loaded = filename;
return true;
}catch(e){ return false;}
}
//预加载
this.preLoad = function(filename){
if(me.loaded=='' || me.loaded!=filename){me.exist(filename);}
return me.loaded;
}
//获取指定的属性值
this.getAtrib = function(filename,atrib){
if(me.preLoad(filename)!='')
{
var val = me.udObj.getAttribute(atrib);
return val==null?"":val;
}return "";
}
//移除对象的指定属性
this.remAtrib = function(filename,atrib){
me.udObj.removeAttribute(atrib);
me.udObj.save(filename); //将对象数据保存到名为filename的XML文件里面
return true;
}
//设置指定的属性值
this.setAtrib = function(filename,atrib,val,expire){
var etime = typeof(expire)=="undefined"?24*60*60:expire;
me.udObj.expires = me.setExpire(etime);
me.udObj.setAttribute(atrib,val);
me.udObj.save(filename);
}
//设置一个系列的对象数据(即整个XML文件)失效
this.remPartion = function(filename){
if(me.exist(filename))
{
me.udObj.expires = me.setExpire(-1);
me.udObj.save(filename);
}
}
//设置有效期
this.setExpire = function(sec){
var oTimeNow = new Date();
oTimeNow.setSeconds(oTimeNow.getSeconds() + parseInt(sec));
return oTimeNow.toUTCString();
}
}else //非IE下用globalStorage实现客户端存储
{
var domain = document.domain;
//获取指定的属性值
this.getAtrib = function(filename,atrib){
var oTimeNow = new Date();
var etime = parseInt(window.globalStorage[domain][filename + "__expire"]);
if(!etime || etime {
me.remPartion(filename);
return '';
}
return window.globalStorage[domain][filename + "__" + atrib];
}
//移除对象的指定属性
this.remAtrib = function(filename,atrib){
try{window.globalStorage.removeItem(filename + "__" + atrib);}catch(e){}//删除
return true;
}
//设置指定的属性值
this.setAtrib = function(filename,atrib,val,expire){
var etime = typeof(expire)=="undefined"?24*60*60:expire;
window.globalStorage[domain][filename + "__expire"] = me.setExpire(etime);
window.globalStorage[domain][filename + "__" + atrib] = val;
}
//设置一个系列的对象数据失效
this.remPartion = function(filename){
me.remAtrib(filename,"expire");
return true;
}
//设置有效期
this.setExpire = function(sec){
var oTimeNow = new Date();
oTimeNow.setSeconds(oTimeNow.getSeconds() + parseInt(sec));
return oTimeNow.getTime();
}
}
}
其中CMInfo类见 一些常用的JS功能函数(一) (2009-06-04更新)
需要说明的是因为还没用到实际项目中,因此还不知其兼容性和稳定性如何,如果网友发现了BUG,还望指出。谢谢

javaandjavascriptaredistinctlanguages:javaisusedforenterpriseandmobileapps,while javascriptifforInteractiveWebpages.1)JavaisComcompoppored,statieldinglationallyTypted,statilly tater astrunsonjvm.2)

JavaScript核心數據類型在瀏覽器和Node.js中一致,但處理方式和額外類型有所不同。 1)全局對像在瀏覽器中為window,在Node.js中為global。 2)Node.js獨有Buffer對象,用於處理二進制數據。 3)性能和時間處理在兩者間也有差異,需根據環境調整代碼。

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

Python和JavaScript的主要區別在於類型系統和應用場景。 1.Python使用動態類型,適合科學計算和數據分析。 2.JavaScript採用弱類型,廣泛用於前端和全棧開發。兩者在異步編程和性能優化上各有優勢,選擇時應根據項目需求決定。

選擇Python還是JavaScript取決於項目類型:1)數據科學和自動化任務選擇Python;2)前端和全棧開發選擇JavaScript。 Python因其在數據處理和自動化方面的強大庫而備受青睞,而JavaScript則因其在網頁交互和全棧開發中的優勢而不可或缺。

Python和JavaScript各有優勢,選擇取決於項目需求和個人偏好。 1.Python易學,語法簡潔,適用於數據科學和後端開發,但執行速度較慢。 2.JavaScript在前端開發中無處不在,異步編程能力強,Node.js使其適用於全棧開發,但語法可能複雜且易出錯。

javascriptisnotbuiltoncorc; sanInterpretedlanguagethatrunsonenginesoftenwritteninc.1)JavascriptwasdesignedAsignedAsalightWeight,drackendedlanguageforwebbrowsers.2)Enginesevolvedfromsimpleterterpretpretpretpretpreterterpretpretpretpretpretpretpretpretpretcompilerers,典型地,替代品。

JavaScript可用於前端和後端開發。前端通過DOM操作增強用戶體驗,後端通過Node.js處理服務器任務。 1.前端示例:改變網頁文本內容。 2.後端示例:創建Node.js服務器。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境