国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

關(guān)于瀏覽器緩存數(shù)據(jù)處理

2019-11-17 03:55:00
字體:
供稿:網(wǎng)友
今天再次回顧了一下瀏覽器緩存數(shù)據(jù)方面的東西,因為有項目要用到,用cookie老大又不允許,所以只能看一下UserData/globalStorage/sessionStorage方面的了,找到一篇寫得比較詳細的文章,再此轉(zhuǎn)載咯。

1.針對IE6以上(含)內(nèi)核的瀏覽器,我們可以使用UserData 行為(userData Behavior)

說明:

userData 行為通過將數(shù)據(jù)寫入一個UserData存儲區(qū)(UserData store)來保存數(shù)據(jù),userData可以將數(shù)據(jù)以xml格式保存在客戶端計算機上,如果你用的是 Windows 2000 或者 Windows xp,是保存在C:/Documents and Settings/Liming/UserData/文件夾下(如果操作系統(tǒng)不是安裝在C盤,那么C就應該是操作系統(tǒng)所在的分區(qū))。該數(shù)據(jù)將一直存在,除非你人為刪除或者用腳本設(shè)置了該數(shù)據(jù)的失效期。userData行為提供了一個比Cookie更具有動態(tài)性和更大容量的數(shù)據(jù)結(jié)構(gòu)。每頁的UserData 存儲區(qū)數(shù)據(jù)大小可以達到64 Kb,每個域名可以達到640 Kb。userData 行為通過sessions為每個對象分配UserData存儲區(qū)。使用save和load方法將UserData存儲區(qū)數(shù)據(jù)保存在緩存(cache)中。一旦UserData存儲區(qū)保存以后,即使IE瀏覽器關(guān)閉或者刷新了,下一次進入該頁面,數(shù)據(jù)也能夠重新載入而不會丟失。出于安全的考慮,相同協(xié)議使用同一個文件夾保存UserData存儲區(qū)數(shù)據(jù)。

使用:

(1)首先必須在行內(nèi)或文檔的head部分聲明如下樣式:
Quote:

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

或者使用如下js代碼來聲明:


Quote:

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



(2)成員:


Quote:

expires 設(shè)置或取得使用userData行為保存數(shù)據(jù)的失效日期,使用方法:對象ID.expires = UTC格式的時間字符串;

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

load(存儲區(qū)名) 從userData存儲區(qū)載入存儲的對象數(shù)據(jù);

removeAttribute() 刪除指定的屬性值;

save(存儲區(qū)名) 將對象存儲到一個userData存儲區(qū);

setAttribute() 設(shè)置指定的屬性值;

XMLDocument 取得存儲該對象數(shù)據(jù)的XML DOM引用




(3)示例:


Quote:

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

document.documentElement.load("t");

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

document.documentElement.save("t");




2.針對Firefox2(含)以上內(nèi)核的瀏覽器,我們可以使用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 上的頁面內(nèi)使用globalStorage[“baidu.com“][“t“]=“test“來賦值,但是到了firefox3這么做卻會得到一個錯誤提示,原因是firefox3的安全策略要求在使用 globalStorage時,指定的域名和實際的域名必須嚴格匹配!

3.Database Storage,HTML5里的內(nèi)容,目前僅有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.

備注:

現(xiàn)代瀏覽器一般默認都支持cookie,但是使用cookie也有幾個致命的弱點:存儲的信息量太少,頁面向服務器發(fā)送請求的同時cookie也會被發(fā)送,無形中浪費用戶的帶寬。

5.其它解決方案

Google Gear:Google開發(fā)出的一種本地存儲技術(shù);

Flash:利用Flash也可以實現(xiàn)本地存儲

這兩種方法的優(yōu)點是:能支持所有的OS和瀏覽器(Google Gear目前僅支持IE5+和Firefox1.5+);缺點是需要用戶安裝額外的插件,使用起來不如前面其它3種方法簡便。



本文來自CSDN博客,轉(zhuǎn)載請標明出處:http://blog.csdn.net/Jack_ljk/archive/2009/12/29/5102286.aspx
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 荣成市| 汤阴县| 广元市| 库尔勒市| 德昌县| 崇左市| 巴林左旗| 万全县| 武邑县| 灵宝市| 定陶县| 济源市| 天等县| 定日县| 峡江县| 加查县| 灵璧县| 万宁市| 阳东县| 勐海县| 南华县| 双鸭山市| 溧阳市| 台南市| 晴隆县| 凤城市| 长沙县| 方山县| 阿图什市| 板桥市| 政和县| 巨鹿县| 茌平县| 旬阳县| 垣曲县| 平泉县| 民县| 隆子县| 舒兰市| 张家港市| 龙泉市|