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

Including VBScript Codes with HTML "script" Tags

This section provides a quick description of how to include VBScript codes into HTML documents with 'script' tags. A tutorial example is provided on calling a function defined in the 'head' tag.

If you want have VBScript code to be executed by IE browser on the client systems, you need to embed VBScript code in HTML documents to be delivered to IE browser.

HTML document language standard supports the "script" tag that allows you to include VBScript code in HTML documents. Both forms of the "script" tag work identically:

<script language="vbscript" ...>
   ... VBScript statements ...
</script>
<script type="text/vbscript" ...>
   ... VBScript statements ...
</script>

In a single HTML document, multiple "script" tags with VBScript codes can be placed in different locations. The exact locations and relations of "script" tags are described in following simple rules:

  • "script" tags can be placed inside the "head" tag.
  • "script" tags can be placed inside many block-level tags, like "body", "p", "pre", "div", etc.
  • "script" tags can be placed inside many level-level tags, like "strong", "em", "span", etc.
  • VBScript codes included in "script" tags in the "head" tag will be executed before the Web page body gets processed.
  • VBScript codes included in "script" tags in the block-level and line-level tags will be executed while the Web page body gets processed.
  • VBScript codes included in "script" tags will be executed in the same order as they appear in the HTML document.
  • VBScript codes from all "script" tags will be considered as a single execution session, as if they were included in a single "script" tag.

Based these rules, we could define a user function in the "head" tag of the document, and call it later in a "pre" tag in the same document. Here is a simple tutorial example that shows this interesting behavior:

<html>
<!-- Hello_World_Head.html
 - Copyright (c) 2015, HerongYang.com, All Rights Reserved.
-->
<head>
<title>printHello() Function in the "head" Tag</title>
<script type="text/vbscript">
function printHello()
   document.write("Hello World!")
end function
</script>
</head>
<body>
<pre>
<script type="text/vbscript">
   printHello()
</script>
</pre>
</body>
</html>

Of course, the output of this sample VBScript page will be a simple text on the page: "Hello World!".

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

Including VBScript Codes with HTML "script" Tags - Updated in 2015, by Dr. Herong Yang