Behaviors simplify Web development in several ways:
Behaviors are available in Internet Explorer (IE) version 5 and above. IE version 5.5 introduced a new type of behavior called element behaviors. This required a name for IE 5 behaviors, so those are now called attached behaviors. Element behaviors let you create custom HTML tags, whereas attached behaviors let you add features (i.e. attributes) to existing HTML elements.
Several of the default behaviors for persisting data raise security concerns: you should not save sensitive data with these objects because they save data in text form, unencrypted.
Default behaviors available with IE 5 include:
| Behavior | Description |
|---|---|
| anchorClick | Enables navigation to a folder view |
| anim | Defines the Microsoft DirectAnimation® viewer so you can render DirectAnimation objects and sounds |
| clientCaps | IE only; used to extract information about features supported by the user's particular version of IE, and provides a way to install browser components |
| download | Downloads a file; can notify a callback function |
| homePage | Used to set the home page, navigate to the home page, and determine if a specified URL is the home page. |
| httpFolder | Navigate to and/or display a folder view for a specified URL |
| mediaBar | Provides UI elements for locating and playing media in the browser. |
| saveFavorite | Persists the current state of a page (using the UserData store), across sessions, when the user saves the page using IE's Favorites->Add to Favorites... menu. Values are restored when the user returns to the page using the Favorites menu or a shortcut. |
| saveHistory | Persists the current state of a page (using the UserData store), for the current session only, when the user navigates away from the page. Values are restored when the user returns to the page using the Back or Forward buttons. |
| saveSnapshot | Persists form values, styles, dynamic content, and scripting variables when the user saves a Web page. |
| userData | Persists information across sessions (using the UserData store). |
You can write your own behaviors. You can write behaviors in any scripting language that supports the Microsoft ActiveX scripting interfaces, including VBScript and JScript (and JavaScript if you are not using any ActiveX scripting interfaces or JScript-specific language features). You can implement behaviors using Microsoft Windows® Script Component (WSC) or Visual C++ also.
The easiest way to implement a behavior is with a .htc (HTC) file. See the Scroller example for a demonstration of how to create a behavior with an HTC file. You will need to read the HTC Reference on Microsoft's Web site to learn about HTC syntax (Navigate to msdn.microsoft.com and look down the navigation menu to Web Development, expand that tree, expand the Behaviors tree, and view the HTC Reference). See the UserData example for a demonstration of how to implement the built-in UserData behavior.