Click to return to the Component Development home page    
Welcome to Scriptlet Tech...    
Web Workshop  |  Component Development

Adding Scriptlets to Your Application


You can use scriptlets as you would any control.

To add a scriptlet to a Web page:

  1. Define the scriptlet using an OBJECT tag, setting its TYPE attribute to "text/x-scriptlet".
  2. Specify the scriptlet's URL by setting the DATA attribute in the OBJECT tag, as in the following example:
    <OBJECT ID="Scriptlet1" 
    TYPE="text/x-scriptlet"
    DATA="http://myserver/sample.htm">

    Or, specify a URL using the object's PARAM tag, as in the following example:

    <OBJECT ID="Scriptlet1" TYPE="text/x-scriptlet" WIDTH=300 HEIGHT=200>
       <PARAM NAME="url" VALUE="http://myserver/sample.htm"
    </OBJECT>
    

    Note If you insert a scriptlet into a Web page using a visual tool such as a toolbox or control insertion dialog box, the resulting object definition might include a CLASSID attribute instead of the TYPE attribute.

To add a 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.

You can add scroll bars if the scriptlet is too small to be displayed within the container object. For details, see scrollbar.

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. 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 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.

Note If you are working in an environment that can display an object's properties and methods, such as 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, 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 Defining Event Handlers.

See Also

Scriptlets Overview

Designing a Scriptlet



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.