Monday, July 12, 2004

Web Development - About Element Behaviors

Element behaviors are one of the most significant new capabilities in Microsoft® Internet Explorer 5.5. They provide the capability to define custom elements, which can be used in the same way as normal HTML elements in a Web page. An element behavior can be written in script using an HTML Component (HTC) file, or it can be implemented with a binary Dynamic HTML (DHTML) behavior. Element behaviors are encapsulated components, so they can add new and interesting functionality to a Web page while improving the organization of content, functionality, and style.

DHTML behaviors were introduced in Internet Explorer 5 and made it possible to modify the behavior of standard HTML elements by setting the behavior attribute of a Cascading Style Sheets (CSS) entry or by using the addBehavior method in script. DHTML behaviors, in the form introduced in Internet Explorer 5, are now referred to as attached behaviors, to distinguish them from element behaviors—which use a different binding mechanism and have other unique characteristics.

Element behaviors can be used to implement anything from a simple rollover effect to a complex interactive component. A special processing instruction is used to import an element behavior into a Web page, where it is synchronously bound to a custom element. Once an element behavior has been downloaded and parsed, it exists as a first-class element in the document hierarchy and remains permanently bound to the custom element. Element behaviors differ significantly from attached behaviors in this respect. An attached behavior binds asynchronously to an element and modifies its behavior, and it can be attached or removed programmatically.

Element behaviors bring several enhancements to the Behavior Component Model in Internet Explorer 5.5. They provide new features that complement the existing capabilities of attached behaviors and provide additional robustness and reliability. However, attached behaviors are not superceded by element behaviors and remain useful in many scenarios.

A special feature of element behaviors, called viewlink, enables a document tree to be encapsulated in an HTC file, separate from the content of the main Web page. This opens up another realm of possibilities that are covered separately in the ViewLink Overview.

An element behavior can be implemented with an HTC file or a binary DHTML behavior, and the techniques used in each approach are quite different. This article is focused on writing element behaviors with HTC files.

No comments: