HTML Components: HTML Behaviors vs. HTC Behaviors
HTML Behaviors vs. HTC Behaviors
HTML Components are encapsulated HTML content that can be rendered in other HTML documents. Before HTML Components, the only way to create custom controls for use in HTML documents was through Microsoft ActiveX Controls. HTML authors had to use the
One of the drawbacks of ActiveX Controls is that they require installation on the client machine before usage. HTML Controls, on the other hand, are downloaded to the client machine with the primary document that the user downloads anyway. HTML Controls are also more attractive to DHTML authors because they can develop their own controls and components in a language they are already familiar with, DHTML.
HTCs provide a simple mechanism to implement DHTML behaviors in script. An HTC file is nothing but an HTML file, saved with an .htc extension, that contains scripts and a set of HTC-specific custom elements. These elements expose properties, methods, and events that define the HTML component. All HTC elements are accessible from script as objects, using their ID attributes. This allows all attributes and methods of HTC elements to be dynamically manipulated through script.
You can use HTCs to implement behaviors that:
- Expose properties and methods. You define them via the
- Expose custom events. These events are defined via the
EVENTelement and are fired back to the containing page, using the element's
fire()method. The environment of the event can be set by the
- Access the containing page's DHTML object model. The object
elementin HTCs returns the element to which the behavior is attached. With this object, an HTC can access the containing document and its object model (properties, methods, and events).
- Receive notifications. When using the
ATTACHelement, the browser notifies the HTC of standard DHTML events as well as two HTC-specific events,
HTCs encapsulate a behavior definition. Behaviors were first delivered in Internet Explorer 5.0. We have introduced behaviors in Column 22, Internet Explorer 5.0 Review, Part I and Column 23, Internet Explorer 5.0 Review, Part II. The advantage of behaviors encapsulated in HTC is that they cannot be removed from their element tags. In IE 5.0, a behavior can be detached from an element via script. In IE 5.5, the elements are always consistent in that they cannot be separated from their original behaviors.
Next: How to create custom tags and namespaces
Produced by Yehuda Shiran and Tomer Shiran
Created: July 3, 2000
Revised: July 3, 2000