Share via


Understanding Scriptlets and Behaviors

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

A scriptlet is a lightweight, reusable Component Object Model (COM) component that consists of HTML code and script and is created according to certain conventions. A behavior is a lightweight component that encapsulates specific functionality. When applied to an HTML element, a behavior enhances the element's default behavior. For Example, with scriptlets you can:

  • Use the graphical and hypertext capabilities of Web pages as visually rich interfaces for your application.
  • Change the appearance and behavior of Web pages from within the host environment.
  • Create prototype controls that you intend to write in other environments. Because you can put scriptlets together quickly and easily, you can test ideas. When you have completed your design, you can re-implement the control in another environment, such as Visual Basic.

Scriptlets and behaviors are very similar in that they both contain script in a separate document that exposes functionality that can be used in a Web page. They differ in that behaviors are STYLE attributes that point to a separate file containing script that is called in response to an event associated with an HTML element. Scriptlets, on the other hand, can be used for almost anything you can do with script in a Web page.

Scriptlets are supported in Microsoft® Internet Explorer 4.0 or later, and behaviors are supported in Internet Explorer version 5 or later. Deciding when to use a scriptlet and when to use a behavior depends on what you are trying to accomplish and what browser you are writing for. If your users are running Internet Explorer 4.x, scriptlets are your only choice. If you want to create a self-contained component for use in HTML, a DHTML scriptlet makes sense. If you want to add a lightweight component to be used as a STYLE attribute, a behavior is a good choice.

In This Section

  • Creating Scriptlets
    A scriptlet is an HTML code file that has either an .sct or an .htm extension. You can create scriptlets by using HTML code and Microsoft® Visual Basic® Scripting Edition (VBScript) code, Microsoft® JScript® code, or both, and you can create them in any HTML editor.
  • Working with DHTML Scriptlets
    A DHTML scriptlet is a Web page that exposes a user interface that can be used from another Web page.
  • Working with Code-Only Scriptlets
    There are two ways to create this kind of scriptlet. You can create an HTML file with <SCRIPT> tags to contain your custom procedures, or you can use the Scriptlet Wizard.
  • How Scriptlets and Web Browser Security Interact
    In a security-aware host such as Microsoft® Internet Explorer 4.0 or later, a scriptlet and any controls contained within it are subject to Internet Explorer security.
  • Understanding Behaviors
    Scriptlets and behaviors provide a way to create reusable components you can use on a Web page.
  • Scripting in Office Applications
    In the past, scripting in Office applications was confined to manipulating Microsoft® Outlook® objects and controls from within an Outlook form.
  • Working with the Microsoft Script Editor
    The Microsoft Script Editor has been added to the Microsoft® Office applications so you can work with the HTML code, DHTML objects, and script in an Office document from within an Office application.