HTML Components: HTML Behaviors vs. HTC Behaviors
HTML Components
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 OBJECT
tag to include ActiveX Controls on their pages. We covered ActiveX Controls in several columns. Columns 21, Embedding Sound in Web Pages, Part I, and 22, Embedding Sound in Web Pages, Part II explain how to embed sound objects in your page. In Column 55, OLE Automation in JavaScript, we taught you how to call external applications such as Word and Excel (encapsulated in ActiveX Controls) from your script. And finally, we showed you how to embed a streaming media jukebox in Column 51, A Streaming Media JukeBox, Column 52, A Streaming Media JukeBox, Part II: Netscape, Column 53, A Streaming Media JukeBox, Part III: Browser-Independent, and Column 54, A Streaming Media JukeBox, Part IV: F-W Properties.
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
PROPERTY
andMETHOD
elements. - Expose custom events. These events are defined via the
EVENT
element and are fired back to the containing page, using the element'sfire()
method. The environment of the event can be set by thecreateEventObject()
method. - Access the containing page's DHTML object model. The object
element
in 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
ATTACH
element, the browser notifies the HTC of standard DHTML events as well as two HTC-specific events,oncontentready
andondocumentready
.
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
URL: https://www.webreference.com/js/column64/2.html