Viewing Scriptlets as Stand-Alone Files

Since scriptlets are pure HTML (and even ASP) files you might think they are immediately visible, although not functional, through any browser. Alas, this is not altogether true.

As you probably know, making pages display properly on a variety of browsers is an endless struggle, and may be an intractable problem not so different from some famous ones from combinatorial analysis.

Yes, scriptlets are Web pages, but if you don't take any reasonable precautions, even IE4 fails to display them as stand-alone documents without errors.

Furthermore, a scriptlet often needs to be initialized via scripting to become significant and start working as you would expect. If you ask Internet Explorer to show it, it's likely you will get an empty page.

Safe-display Scriptlets

The problem lies in the fact that scriptlets exploit a specific property of the

window
object, which is the root of the IE4 Scripting Object Model. IE4 only initializes this property properly if the page contains a scriptlet. Consequently, when the scriptlet is displayed as a normal Web page, sooner or later it will attempt to access an inconsistent or undefined object causing the browser to complain.

Fig. 4.7 – Error while viewing scriptlets as stand-alone files with IE4.

The message box doesn't reveal which is the missing property or method. It is

window.external
which makes the difference between the scriptlets and the traditional HTML pages.

Such an error only occurs with scriptlets that are not safe for display. And, of course, if you attempt to view them with browsers other than IE4.

Fig. 4.8 – Attempting to view scriptlets as stand-alone files with Navigator 4.02.

To avoid these error messages you should be careful while accessing objects in your scriptlets code. We'll be covering this aspect in more detail later.

© 1997 by Wrox Press. All rights reserved.