What is Scripting For?

Technically speaking, what we have just designed and implemented is an enhancement of a normal HTML page, which exploits the power of the DHTML object model. It puts together and manipulates standard elements, in order to give us some non-standard, and even useful, behaviors. So, how does scripting relate to this?

Scripting languages are the glue for manipulating and automating these system objects. Thanks to the open architecture of the ActiveX Scripting engine, IE4 allows you to use literally any scripting language you may know. In fact, you can use and mix VBScript, JavaScript, Perl, maybe Python, or even Rexx, for writing scripts to be used in DHTML documents. This is not at all a secondary consideration, especially in the context of large scale Web-based projects. In addition, the language-independence is a precise requirement of the W3C, the standards authority for DHTML.

As you probably already know, IE4 only natively supports VBScript and JScript, which is Microsoft's implementation of JavaScript and is nearly identical to it. To find out more about both JScript and VBScript you might check the respective Web sites at:

http://www.microsoft.com/jscript http://www.microsoft.com/vbscript

To be able to exploit other scripting languages, such as Perl, you need to install a proper parser DLL which supports the interfaces required by the ActiveX Scripting engine. Of course, to have your script code executed on other machines you should make sure that the same engine is installed on them.

It's worth asking 'what can scripting do for me?' Scripting plays a fundamental role in enhancing DHTML documents with customized and built-in behaviors. Don't forget that scripting lets you do what you want to do with your pages.

Combining scripts and objects

When programming, you have two distinct players on the ground: scripting and standard DHTML objects. By combining them, you can get attractive, useful behaviors from your pages. What we showed above demonstrates just this.

Unfortunately, though, if you want to reuse that bitmapped anchor in another DHTML document, you have to cut-and-paste at least the four

<SCRIPT>
tags. Furthermore, some other minor code adjustments are also required, since you should adapt the scripts to the specific
<IMG>
tag they link to. In fact, it's reasonable to expect that a different ID is involved, and—above all—different images.

Scripts and DHTML objects are a powerful mixture, but we all need a better way to allow us to express and exploit their potential. Earlier we deliberately often used the term "behavior". In particular, at the beginning of this paragraph there's a sentence that sounds like this

By combining [scripts and objects], you can get attractive, useful behaviors from your pages.

It's a great truth. Until you have more powerful and flexible tools, the best that you can get from your DHTML pages is specialized behaviors. Passing from document to document you can reproduce them, even quickly and easily, but nothing more than this. In fact, 'reproducing a behavior' is like cut-and-paste, and is more akin to recycling than reusing.

Instead, what we need is object-oriented reusability, which will allow us to build self-contained components by marrying up scripting and DHTML.

© 1997 by Wrox Press. All rights reserved.