VBScript Tutorials - Herong's Tutorial Examples - v6.02, by Herong Yang
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