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: