store.js is an implementation of the JavaScript API package locally stored browser, not by Cookie and Flash technology, but the use of localStorage, globalStorage and userData behavior.
Sample code:
// Store 'marcus' at 'username'
store.set('username', 'marcus')
// Get 'username'
store.get('username')
// Remove 'username'
store.remove('username')
// Clear all keys
store.clear()
// Store an object literal - store.js uses JSON.stringify under the hood
store.set('user', { name: 'marcus', likes: 'javascript' })
// Get the stored object - store.js uses JSON.parse under the hood
var user = store.get('user')
alert(user.name + ' likes ' + user.likes)
UserData
Applications
Microsoft IE UserData is dedicated to open in the system a storage space, so that only support a combination of Windows + IE, the actual test in 2000 (IE5.5), XP (IE6, IE7), Vista (IE7) are possible normal use.
Where?
In XP, usually located in C: \ Documents and Settings \ username \ UserData, some time will be in C: \ Documents and Settings \ username \ Application Data \ Microsoft \ Internet Explorer \ UserData.
In Vista, located at C: \ Users \ username \ AppData \ Roaming \ Microsoft \ Internet Explorer \ UserData.
capacity
Web production complete manual says:
Security Zone |
Document Limit (KB) |
Domain Limit (KB) |
Local Machine |
128 |
1024 |
Intranet |
512 |
10240 |
Trusted Sites |
128 |
1024 |
Internet |
128 |
1024 |
Restricted |
64 |
640 |
When using the line, single file size limit is 128KB, the next domain name can save the file 1024KB total, the number of files should be no restrictions. In the Restricted Sites where these two values are 64KB and 640KB, so if you take into account a variety of situations, it is best to control a single file 64KB or less.
how to use?
You can create an object that supports UserData JS with the following statement:
o = document.createElement('input');
o.type = "hidden";
o.addBehavior ("#default#userData");
//UserData.o.style.behavior = "url('#default#userData')" ;
//上面的语句也是一样的作用
document.body.appendChild(o);
To put it plainly UserData is in the style of a Behavior, so this writing is the same:
<input type=hidden class= storeuserData />
<style>
.storeuserData {behavior:url(#default#userData);}
</style>
UserData can be bound in most html tags, in particular:
A, ACRONYM, ADDRESS, AREA, B, BIG, BLOCKQUOTE, BUTTON, CAPTION, CENTER, CITE, CODE, DD, DEL, DFN, DIR, DIV, DL, DT, EM, FONT, FORM, hn, HR, I, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, KBD, LABEL, LI, LISTING, MAP, MARQUEE, MENU, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, Q, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TEXTAREA, TT, U, UL, VAR, XM
UserData object has the following attributes and methods:
Attributes |
description |
Set or read a file expiration |
|
Reads the XML DOM document |
method |
description |
Reading the value of the specified property |
|
open a file |
|
Deletes the specified property |
|
save document |
|
For the specified property assignment |
UserData file is actually an XML file, the file name - save string> how properties, such as the following piece of code:
o.setAttribute("code", "hello world!");
o.save("baidu");
After the execution, the UserData folder will generate a baidu [1] .xml file, the contents of which are:
<ROOTSTUB code="hello,world!"/>
In a file can have multiple attributes, i.e. it may store various different data.
Link to save the music box item, the class encapsulates a UserData, which can more easily use the UserData, the following code:
/** @class 定义userdata的操作 */
var UserData = {
// 定义userdata对象
o : null,
// 设置文件过期时间
defExps : 365,
// 初始化userdate对象
init : function(){
if(!UserData.o){
try{
UserData.o = document.createElement('input');
UserData.o.type = "hidden";
//UserData.o.style.behavior = "url('#default#userData')" ;
UserData.o.addBehavior ("#default#userData");
document.body.appendChild(UserData.o);
}catch(e){
return false;
}
};
return true;
},
// 保存文件到userdata文件夹中 f-文件名,c-文件内容,e-过期时间
save : function(f, c, e){
if(UserData.init()){
var o = UserData.o;
// 保持对象的一致
o.load(f);
// 将传入的内容当作属性存储
if(c) o.setAttribute("code", c);
// 设置文件过期时间
var d = new Date(), e = (arguments.length == 3) ? e : UserData.defExps;
d.setDate(d.getDate()+e);
o.expires = d.toUTCString();
// 存储为制定的文件名
o.save(f);
}
},
// 从uerdata文件夹中读取指定文件,并以字符串形式返回。f-文件名
load : function(f){
if(UserData.init()){
var o = UserData.o;
// 读取文件
o.load(f);
// 返回文件内容
return o.getAttribute("code");
}
},
// 检查userdata文件是否存在 f-文件名
exist : function(f){
return UserData.load(f) != null;
},
// 删除userdata文件夹中的指定文件 f-文件名
remove : function(f){
UserData.save(f, false, -UserData.defExps);
}
// UserData函数定义结束
};
Reproduced in: https: //my.oschina.net/tiwer/blog/199859