Freigeben über


saveFavorite Behavior

This topic documents a feature of Binary Behaviors, which are obsolete as of Internet Explorer 10.

Enables the object to persist data in a favorite Web site.

Syntax

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")

Possible Values

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.

Property Description
XMLDocument Retrieves a reference to the XML
Event Property 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.

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 Windows 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 note 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 Microsoft Internet Explorer 5, in the Microsoft Win32 and Unix platforms.

Example

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>

Code example: https://samples.msdn.microsoft.com/workshop/samples/author/persistence/saveFavorite_1.htm

Applies To

A, ABBR, 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

See Also

Introduction to DHTML Behaviors, Introduction to Persistence