The <OBJECT> Tag

Since both ActiveX controls and scriptlets are inserted through the same tag, how does the browser distinguish between them? The following is a declaration for an ActiveX control.

<object
  id="Button1" 
  classid="CLSID:D7053240-CE69-11CD-A777-00DD01143C57"
  width="70" 
  height="32">
  <param name="Caption" value="Click Me!">
</object>

What makes the component uniquely identifiable, and constitutes an indirect reference to the actual file name, is the content of the classid attribute. It contains a 128-bit number: CLSID, which is used to retrieve the name of the executable module in the Windows registry.

A scriptlet is, instead, embedded through the following code:

<object 
  id="First1"
  data="first.htm" 
  width="100" 
  height="100" 
  type="text/x-scriptlet">
</object>

As you can see, there are a couple of key differences. The first one is the presence of data instead of classid; the second is the specific MIME type used. data refers to the straight file name that implements the component. Although we recommend that you put the container page and the scriptlet in the same directory, there is a way to specify an indirect path for the scriptlet file. For example, the following code:

<object 
  id="First1"
  data="..\first.htm" 
  width="100" 
  height="100" 
  type="text/x-scriptlet">
</object>

tells Internet Explorer 4.0 to search for the file first.htm in the folder immediately above the current one.

This is not the only way of inserting scriptlets into your pages. Here's an alternative method.

<object 
  id="First1"
  width="100" height="100" 
  type="text/x-scriptlet"> 
  <PARAM NAME="url" VALUE="http://www.server.com/first.htm">
</object>

Instead of data, it makes use of a url property. Behind the scenes, there's an ActiveX control that actually hosts the scriptlet. In this case, we're simply working directly with the properties of this scriptlet Control. The property url is assigned the URL from which the code should be taken. Of course, the file can also reside locally.

Inserting a scriptlet this way gives you the opportunity to set some additional properties of the scriptlet Control at design-time. For example, with this method you can decide whether a scrollbar should be used if the scriptlet is too big to fit in the client area, or whether the content should be made selectable.

<object 
  id="First1"
  width="100" height="100" 
  type="text/x-scriptlet"> 
  <PARAM NAME="url" VALUE="http://www.server.com/first.htm">
  <PARAM NAME="selectableContent" VALUE="1">
</object>

Aside from the URL, these properties are also available at run-time. Actually, they form the ambient properties a scriptlet can access through the aforementioned external object. All these topics, however, will be discussed in more detail in Chapter 7 – Container and Ambient Properties.

© 1997 by Wrox Press. All rights reserved.