Adding DHTML Scriptlets to Your Application

See Also

After you have created a DHTML scriptlet, you can use it in your applications. You must first create a scriptlet container object. This object creates a window for the scriptlet and provides a way for the host application to specify where the scriptlet displays, at what size, and so on.

To add a DHTML scriptlet to a host application

  1. Create a scriptlet container object in your application and set its Name property.

  2. Set the scriptlet container object's url property to the URL of the scriptlet you want to use.

Important   If you are adding the scriptlet to a Web page, do not set the url property to the URL of the current page. Doing so causes a recursive call to the page and will cause the browser to stop functioning.

If you are working with a Web page, you can use the <OBJECT> tag to reference the scriptlet. You can add a scriptlet to the Microsoft® Visual InterDev™ Toolbox.

To add a DHTML scriptlet to the Toolbox

Alternatively, you can create an <OBJECT> tag yourself that references the scriptlet.

To refer to a DHTML scriptlet in an <OBJECT> tag

Working with the Scriptlet Container Object

In your application, the DHTML scriptlet appears within a scriptlet container object. This object provides you with an interface to the scriptlet. For example, when an event occurs in the scriptlet (and if the scriptlet is forwarding the event), your application sees the event occurring in the container object.

You can manage the appearance of the scriptlet by setting properties of the scriptlet container object. In some cases, you can set properties within the scriptlet's scripts to manage its own appearance.

You can add scrollbars if the scriptlet does not fit within the container object. For details, see scrollbar property. You can also resize the container object from within the scriptlet by using a script to set the DHTML script object's pixelHeight and pixelWidth properties. For example, the following example shows how you can resize the scriptlet container when the scriptlet is first loaded:

<HTML ID="MyPage">
<HEAD>
<SCRIPT LANGUAGE="VBScript">
Sub window_onload()
   MyPage.style.pixelHeight = 300
   MyPage.style.pixelWidth = 400
End Sub
</SCRIPT>
</HEAD>

If you change the .htm file after creating the control, the display in the control is not updated until the next time the page is read. This occurs when the application is run or if you change the url property of the control again.

Note   After the scriptlet has been initialized, the F5 key, used to refresh a page in Microsoft® Internet Explorer, is not active in the scriptlet container object.

After creating an instance of the scriptlet, you can write scripts for it as you would for any other control. The object you are using to work with properties and methods is the scriptlet container object; the exact properties and methods you can use are defined by the scriptlet identified in the container's url property. If you are working in an environment that can display an object's properties and methods, such as Microsoft® Visual Basic®, you will not see the properties, because these are not exposed to the development environment.

For example, the following code in a Visual Basic form sets a property and calls a method in the page referenced by the ScriptContainer1 control:

Sub cmdColor_Click()
   ScriptContainer1.BackgroundColor="red"
   ScriptContainer1.UpdateText (Text1.Text)
End Sub

Note   In Visual Basic, you must pass a parameter to a scriptlet method even if the method does not require one, or errors can occur. For example, the following statement passes a placeholder parameter of zero to a scriptlet method that does not require parameters:

ScriptContainer1.ToggleColor (0)

Before getting a scriptlet's properties or calling its methods, you must be sure that the scriptlet has been fully loaded. For details, see the container object's onreadystatechange event and readyState property, and the scriptlet's frozen property.

Handling events that occur in the scriptlet is slightly different than it is for events in other objects. For details, see Exposing Events in DHTML Scriptlets.