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.
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 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.