Use userData to save form data on the client
Author:BencalieSorting date:June 15, 2004
For most users who make webpages, the information stored on the webpage form on the client is mostly implemented using the Cookie technology. These functions include the option selected in the drop-down list box, text box input data. In fact, we can use the userData behavior in the default behavior of Microsoft DHTML to implement this function.
Many netizens have sorted out these questions and provided three examples. The following describes how to use this behavior:
UserData Behavior (userData Behavior ):
1. Description:
UserData writes data to a UserData store to save the data. UserData can save the data in XML format on the client computer, if you are using Windows 2000 or Windows XP, it is saved in the C: \ Documents Ents and Settings \ Liming \ UserData \ folder (if the operating system is not installed on drive C, C should be the partition of the operating system ).
This data will always exist unless you manually delete the data or use a script to set the expiration time of the data.
UserData provides a more dynamic and large data structure than cookies. The size of each page's UserData storage area can reach 64 Kb, and each domain name can reach 640 Kb.
UserData behavior allocates a UserData storage area for each object through sessions. Use the save and load methods to save the UserData stored in the cache. Once the UserData storage area is saved, even if the IE browser is closed or refreshed, the next time you enter the page, the data can be reloaded without being lost.
For security reasons, the same protocol uses the same folder to save data in the UserData storage area.
For security reasons, a UserData store is available only in the same directory and with the same protocol used to persist the store.
When userData is applied to HTML, HEAD, TITLE, and STYLE tags, an error occurs when the save and load methods are used.
Setting the userData behavior (proposed) class on the HTML, HEAD, TITLE, or STYLE object causes an error when the save or load method is called.
The following style must be announced in the line or in the HEAD section of the document:
<STYLE>
. UserData {behavior: url (# default # userdata );}
</STYLE>
UserData behavior can be used by Microsoft? Win32? And IE 5.0 or later versions on Unix platforms. Netscape is not supported.
2. Syntax:
HTML <element style = "behavior: url ('# default # userdata')" ID = sID>
Script object. style. behavior = "url ('# default # userdata ')"
Object. addBehavior ("# default # userData ")
Note: The sID parameter is a unique id that describes the tag. ID is optional, but you can easily control the flag in the script.
3. Members:
Expires
Set or obtain the expiration date for storing data using userData.
Script syntax: object ID. expires = parameter
The parameter is a string that uses the Universal Time Coordinate format to indicate the expiration date. This attribute can be read and written, with no default value. The browser compares this date with the current date. If it expires, the data will automatically expire.
GetAttribute ()
Obtains the specified property value.
Load (storage zone name)
Load the stored object data from the UserData storage area.
RemoveAttribute ()
Deletes a specified property value from an object.
Save (storage zone name)
Store object data in a UserData storage area.
SetAttribute ()
Set the specified property value.
XMLDocument
Obtain the xml dom reference that stores the object data.
For detailed usage, see MSDN (http://msdn.microsoft.com)
Text tag example:
<HTML>
<HEAD>
<STYLE>
. UserData {behavior: url (# default # userdata );}
</STYLE>
<SCRIPT>
Function fnSaveInput (){
Var oPersist = oPersistForm. oPersistInput;
OPersist. setAttribute ("sPersist", oPersist. value); // store oPersist. value as the sPersist attribute
OPersist. save ("oXMLBranch"); // it is stored in the UserData storage area named oXMLBranch.
}
Function fnLoadInput (){
Var oPersist = oPersistForm. oPersistInput;
OPersist. load ("oXMLBranch"); // load it in the UserData storage area named oXMLBranch
OPersist. value = oPersist. getAttribute ("sPersist"); // assign the sPersist attribute to oPersist. value.
}
</SCRIPT>
</HEAD>
<BODY>
<Form id = "oPersistForm">
<Input class = "userData" TYPE = "text" ID = "oPersistInput">
<Input type = "button" VALUE = "Load" onclick = "fnLoadInput ()">
<Input type = "button" VALUE = "Save" onclick = "fnSaveInput ()">
</FORM>
</BODY>
</HTML>
Example 2: Application of Checkbox flag
<Style>
. UserData {behavior: url (# default # userdata );}
</Style>
<Input type = checkbox id = chkbox1 class = userData>
<Script>
Var obj = document. all. chkbox1;
Obj. attachEvent ('onclick', saveChecked)
Function saveChecked (){
Obj. setAttribute ("bCheckedValue", obj. checked );
Obj. save ("oChkValue ");
}
Window. attachEvent ('onload', loadChecked)
Function loadChecked (){
Obj. load ("oChkValue ");
Var chk = (obj. getAttribute ("bCheckedValue") = "true ")? True: false;
Obj. checked = chk;
}
</Script>
Example 3: Select tag application
<Style>
. UserData {behavior: url (# default # userdata );}
</Style>
<Select id = "select1" class = "userData">
<Option> option1 </option>
<Option> option2 </option>
<Option> option3 </option>
<Option> option4 </option>
</Select>
<Script>
Var obj = document. all. select1;
Obj. attachEvent ('onchang', saveSelectedIndex)
Function saveSelectedIndex (){
Obj. setAttribute ("sSelectValue", obj. selectedIndex );
Obj. save ("oSltIndex ");
}
Window. attachEvent ('onload', loadSelectedIndex)
Function loadSelectedIndex (){
Obj. load ("oSltIndex ");
Obj. selectedIndex = obj. getAttribute ("sSelectValue ");
}
</Script>