分享
 
 
 

关于浏览器缓存数据处理

王朝学院·作者佚名  2010-01-01
窄屏简体版  字體: |||超大  

今天再次回顾了一下浏览器缓存数据方面的东西,因为有项目要用到,用cookie老大又不允许,所以只能看一下UserData/globalStorage/sessionStorage方面的了,找到一篇写得比较详细的文章,再此转载咯。

1.针对IE6以上(含)内核的浏览器,我们可以使用UserData 行为(userData Behavior)

说明:

userData 行为通过将数据写入一个UserData存储区(UserData store)来保存数据,userData可以将数据以XML格式保存在客户端计算机上,如果你用的是 Windows 2000 或者 Windows XP,是保存在C:\Documents and Settings\Liming\UserData\文件夹下(如果操作系统不是安装在C盘,那么C就应该是操作系统所在的分区)。该数据将一直存在,除非你人为删除或者用脚本设置了该数据的失效期。userData行为提供了一个比Cookie更具有动态性和更大容量的数据结构。每页的UserData 存储区数据大小可以达到64 Kb,每个域名可以达到640 Kb。userData 行为通过sessions为每个对象分配UserData存储区。使用save和load方法将UserData存储区数据保存在缓存(cache)中。一旦UserData存储区保存以后,即使IE浏览器关闭或者刷新了,下一次进入该页面,数据也能够重新载入而不会丢失。出于安全的考虑,相同协议使用同一个文件夹保存UserData存储区数据。

使用:

(1)首先必须在行内或文档的head部分声明如下样式:

Quote:

.userData {behavior:url(#default#userdata);}

或者使用如下js代码来声明:

Quote:

document.documentElement.addBehavior(”#default#userdata”);

(2)成员:

Quote:

expires 设置或取得使用userData行为保存数据的失效日期,使用方法:对象ID.expires = UTC格式的时间字符串;

getAttribute() 取得指定的属性值;

load(存储区名) 从userData存储区载入存储的对象数据;

removeAttribute() 删除指定的属性值;

save(存储区名) 将对象存储到一个userData存储区;

setAttribute() 设置指定的属性值;

XMLDocument 取得存储该对象数据的XML DOM引用

(3)示例:

Quote:

document.documentElement.addBehavior("#default#userdata");

document.documentElement.load("t");

document.documentElement.setAttribute("value", "test");

document.documentElement.save("t");

2.针对Firefox2(含)以上内核的浏览器,我们可以使用globalStorage

说明:

This is a global object (globalStorage) that maintains multiple private storage areas that can be used to hold data over a long period of time (e.g. over multiple pages and browser sessions).

Specifically, the globalStorage object provides access to a number of different storage objects into which data can be stored. For example, if we were to build a web page that used globalStorage on this domain (developer.mozilla.org) we’d have the following storage object available to us:

globalStorage[’developer.mozilla.org’] - All web pages within the developer.mozilla.org sub-domain can both read and write data to this storage object.

使用:

globalStorage[location.hostname]["t"] = “test”;//赋值

var ret = globalStorage[location.hostname]["t"];//取值

globalStorage.removeItem("t");//删除

备注:

在firefox2 中,我们可以在tc-eb-test00.tc.baidu.com 上的页面内使用globalStorage[“baidu.com“][“t“]=“test“来赋值,但是到了firefox3这么做却会得到一个错误提示,原因是firefox3的安全策略要求在使用 globalStorage时,指定的域名和实际的域名必须严格匹配!

3.Database Storage,HTML5里的内容,目前仅有Safari支持

说明:

This section is non-normative.

4.针对其它浏览器,如常见的Opera,我们可以使用Cookie

说明:

A cookie is a small piece of information stored by the browser. Each cookie is stored in a name=value; pair called a crumb—that is, if the cookie name is “id” and you want to save the id’s value as “this”, the cookie would be saved as id=this. You can store up to 20 name=value pairs in a cookie, and the cookie is always returned as a string of all the cookies that apply to the page. This means that you must parse the string returned to find the values of individual cookies.

Cookies accumulate each time the property is set. If you try to set more than one cookie with a single call to the property, only the first cookie in the list will be retained.

You can use the Microsoft® JScript® split method to extract a value stored in a cookie.

备注:

现代浏览器一般默认都支持cookie,但是使用cookie也有几个致命的弱点:存储的信息量太少,页面向服务器发送请求的同时cookie也会被发送,无形中浪费用户的带宽。

5.其它解决方案

Google Gear:Google开发出的一种本地存储技术;

Flash:利用Flash也可以实现本地存储

这两种方法的优点是:能支持所有的OS和浏览器(Google Gear目前仅支持IE5+和Firefox1.5+);缺点是需要用户安装额外的插件,使用起来不如前面其它3种方法简便。

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Jack_ljk/archive/2009/12/29/5102286.aspx

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有