Behavior Code

y now I am sure that many Visual Basic developers are leveraging their Visual Basic skills to do some Web development. In this Solution, I’ll cover DHTML Behaviors, a new feature of Internet Explorer 5 that can be used in a Visual Basic DHTML application, Browser control, or HTML pages. (Just remember that it’s IE5-specific.) I will introduce the concepts of a Behavior from a Visual Basic developer’s perspective and help you further leverage your skills into this new and cool technology.

Behaviors allow you to add custom interfaces to any Element of an HTML document. The custom interface can include properties, methods, events, and event handlers. Once the Behavior is attached to an Element, the Behavior’s interface blends seamlessly with the Element’s standard interface. So an HTML page author can manipulate the Elements custom interface through script with the standard Element.Method syntax. A Behavior can control the element that it is attached to. It can also control the entire page through the DHTML object model’s top-level Window object. First I’ll explain how to create a Behavior and then I’ll discuss how to attach it to an Element.

Creating a Behavior
A behavior is not written within the HTML page, but rather is stored in a separate file with an .htc extension. The Behavior is structured in a tagged format. The entire Behavior is enclosed in tags. Following the opening tag is the Declarations section, in which you must declare any procedures that will be part of the Behavior’s public interface. After the Declarations section is the scripting section which is enclosed in < /PUBLIC:COMPONENT>

There are four types of procedure declarations:


This declaration is used for methods and must have a matching procedure within the script tags. The Name attribute should be the name of the matching procedure.


This declaration is used for properties, and must have two procedures: one for the Property Let and one for the Property Get. The Get attribute should be the name of the Get procedure and the Put attribute should be the name of the Let procedure. The procedures do not have to be prefixed with let, get, or put.


This declaration is used to declare events. A procedure within the Behavior must raise the event in order for it to fire. The syntax for raising an event is the Event's ID attribute followed by fire, e.g. Event_1.fire


This declaration is used to allow the Behavior to respond to events within the document. In the Event tag, specify the event that you want to handle. In the For attribute, specify the object which raises the event, this may be either the Element (attached to the Behavior), Window, or Document objects. The OnEvent attribute should be the name of the function within the behavior that handles the event.

Attaching a Behavior
Behaviors are integrated with HTML Styles, so that you can attach a behavior through a style. The syntax is:

BEHAVIOR:URL(MyBehavior.htc).

To attach a behavior stored in a file named MyBehavior.htc to a Link Element using an inline style, you would use the following syntax:

DevX.

If the behavior is not in the same directory as the HTML page, then specify the directory path.

Sample Behavior
Here's a sample Behavior that allows an Element to hide or show its child elements. To see it in action (if you are running IE5) click here.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS