Enables the object to persist data in a favorite Web site. dhtml语法 XML |
<Prefix:
CustomTag ID=sID STYLE="behavior:url('#default#savefavorite')" />
|
---|
HTML |
<ELEMENT STYLE="behavior:url('#default#saveFavorite')" ID=sID> |
---|
Scripting | object.style.behavior = "url('#default#savefavorite')" |
---|
object.addbehavior ("#default#savefavorite") |
dhtml可能的值 prefix | prefix that associates the CustomTag with an XML namespace. This prefix is
set using the xmlns attribute of the HTML
tag.
| CustomTag | User-defined tag. | sID | String that specifies a unique identifier for the object. | |
Members Table
The following table lists the members exposed by the
saveFavorite
object. Click a tab on the left to choose the type of member you want to view. Attributes/Properties Property | Description |
---|
XMLDocument |
Retrieves a reference to the XML Document Object Model (DOM) exposed by the object. |
Events Event | Description |
---|
onload |
Fires from a persistent element when the page reloads. | onsave |
Fires from a persisted element when the Web page is saved or bookmarked, or when the user navigates away from the page. |
Methods Method | Description |
---|
getAttribute |
Retrieves the value of the specified attribute. | removeAttribute |
Removes the specified attribute from the object. | setAttribute |
Sets the value of the specified attribute. |
Remarks The saveFavorite behavior allows the current state of a page to be saved when the user adds the page to the Favorites menu. When the user returns to the page through a shortcut or the Favorites menu, the state of the page is restored. The saveFavorite behavior persists data across sessions, using one userdata store for each object. if two objects try to use the same attribute, both are persisted in the userdata store for each element. the savefavoriteuserdata store is persisted in the favorites .ini file, which includes the url of the page as well as the userdata store. when the page is loaded through a shortcut or the favorites menu, the data from the userdata store is loaded from the .ini file, even if the user closes and reopens microsoft® internet explorer. for example, a page with several dynamically updated styles can save these updates using the onload and onsave events. the style values can be saved as attributes when onsave fires, and restored when onload fires. Security Alert Using this behavior incorrectly can compromise the security of your application. This behavior uses a userData store, which is not encrypted and therefore not secure. Any application that has access to the drive where userData is saved has access to the data.
Therefore, it is recommended that you not persist sensitive data like credit card numbers. For more information, see security considerations: dhtml and default behaviors. to persist the state of a page by adding it to the browser favorites menu, first define a cascading style sheets (css) style that applies the savefavorite behavior. then use this style in the tags containing content that needs to be persisted. the required style can be set inline or in the document header, as follows:
<STYLE>
.sFavorite {behavior:url(#default#savefavorite);}
</STYLE> An id is optional for savefavorite, but including one improves performance. the savefavorite behavior is available as of internet explorer 5, in the microsoft win32® and unix platforms.
DHTML代码范例
This example uses the saveFavorite behavior to persist information after the user saves the page as a favorite. <HTML>
<HEAD>
<STYLE>
.sFavorite {behavior:url(#default#savefavorite);}
</STYLE>
<SCRIPT>
function fnSaveInput(){
oPersistInput.setAttribute("sPersistValue",oPersistInput.value);
}
function fnLoadInput(){
oPersistInput.value=oPersistInput.getAttribute("sPersistValue");
}
</SCRIPT>
</HEAD>
<BODY>
<INPUT class=sFavorite onsave="fnSaveInput()" onload="fnLoadInput()" type=text id=oPersistInput>
</BODY>
</HTML> This feature requires Microsoft® Internet Explorer 5 or later. Click the following icon to install the latest version. Then reload this page to view the sample.
applies to |
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,
XMP | |
更多语法参考 introduction to dhtml behaviors, Introduction to Persistence
|