VBScript Support in IE Web Browsers

This section provides a quick description of how IE browser execute VBScript code, provide DOM API for document interaction, and provide events to trigger VBScript code execution.

Earlier in this book, I mentioned that the Internet Explorer (IE) browser is provides a VBScript host environment that allows you to run VBScript code to do client-side scripting on Web pages.

Most of my tutorial examples in previous chapters were actually written to be executed in the IE browser. But we haven't discussed in details what types of VBScript supports are provided by the IE browser.

After learning VBScript language fundamentals, now it's time to see what the IE browser can do for us:

Let's use a simple VBScript example to illustrate those areas:

<html>
<!-- IE_and_VBScript.html
 - Copyright (c) 1998 HerongYang.com. All Rights Reserved.
-->
<head>
<title>VBScript Supports in IE</title>
<script language="vbscript">
dim colorID
colorID = 0
function changeColor()
   if colorID = 0 then
      document.body.bgColor = "lightgrey"
   elseif colorID = 1 then
      document.body.bgColor = "lightblue"
   elseif colorID = 2 then
      document.body.bgColor = "lightgreen"
   elseif colorID = 3 then
      document.body.bgColor = "lightyellow"
   end if
   colorID = (colorID+1) mod 4
end function
</script>
</head>
<body>
<p>
<script language="vbscript">
   document.write("Hello World!")
</script>
</p>
<form>
  <input type="button" value="Click to change background color"
   onClick="changeColor()" language="vbscript"/>
</form>
<p>Want to know the color name? 
<a href="vbscript:msgbox(document.body.bgColor)">Click here.</a>
</p>
</body>
</html>

Run this VBScript example in IE browser, and click the change color button. The browser will change the background color of the page each time you click the button.

If you want to know the code value of the current background color, you can click the hyper link near the end of the page.

Now look at the VBScript example again. The browser indeed supports you in 4 areas:

1. Executes the VBScript code included in the "script" tag while rendering the HTML document:

<script language="vbscript">
   document.write("Hello World!")
</script>

2. Provides the "document" object as part of the DOM API to allow the VBScript code to interact with the HTML document:

   document.write("Hello World!")
   document.body.bgColor = "lightgrey"
   ...

3. Provides the "onClick" event to allow the VBScript code to be executed:

  <input type="button" value="Click to change background color"
   onClick="changeColor()" language="vbscript"/>

4. Executes the VBScript code included in "vbscript:" pseudo-URL.

<a href="vbscript:msgbox(document.body.bgColor)">Click here.</a>

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

 Variable Declaration and Assignment Statement

 Expression and Order of Operation Precedence

 Statement Syntax and Statement Types

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

 Conditional Statements - "If ... Then" and "Select Case"

 Loop Statements - "For", "While", and "Do"

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

IE Web Browser Supporting VBScript

VBScript Support in IE Web Browsers

 Including VBScript Code with HTML "script" Tags

 Including VBScript Code as External Files

 DOM API - The "document" Object

 DOM API - The "window" Object

 Event Listeners and Objects

 'vbscript:' Pseudo-URL Addresses

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)

 References

 Full Version in PDF/EPUB