VBScript Tutorials - Herong's Tutorial Examples - Version 5.20, by Dr. Herong Yang

VBScript Support in IE Web Browsers

This section provides a quick description of how IE browser execute VBScript codes, 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:

  • IE supports <script> tags in the HTML document to execute VBScript codes while rendering the HTML document.
  • IE supports DOM (Document Object Model) API (Application Programming Interface) to allow VBScript codes to interact with the browser and the HTML document.
  • IE supports events to trigger executions of VBScript codes while user interacts with the browser.
  • IE Supports "vbscript:" pseudo-URL - evaluating VBScript code in the address field of the browser.

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

<html>
<!-- IE_and_VBScript.html
 - Copyright (c) 2015, 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 Codes with HTML "script" Tags

 Including VBScript Codes 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

 Printable Copy - PDF Version

VBScript Support in IE Web Browsers - Updated in 2015, by Dr. Herong Yang