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

Including VBScript Codes as External Files

This section provides a quick description of how to save VBScript codes into separate files and include them into HTML documents with 'script' tags. A tutorial example is provided on calling a function stored in a separate VBScript file.

Sometime, if you have a large amount of VBScript code that needs to be shared by multiple HTML documents, you can store the VBScript code in a separate file, and use the "script" tag to retrieve this tile.

The syntax of the "script" tag to retrieve a separate VBScript code file looks like this:

<script type="text/vbscript" src="VBScript_file_URL">
</script>

To test this feature, I wrote this VBScript code and saved as a file, Hello_World_Function.vbs:

function printHello()
   document.write("Hello World!")
end function

Now I can modify my HTML document in the previous section to retrieve this file with a "script" tag:

<html>
<!-- Hello_World_Include.html
 - Copyright (c) 2015, HerongYang.com, All Rights Reserved.
-->
<head>
<title>printHello() Function in an Include File</title>
<script type="text/vbscript" src="Hello_World_Function.vbs">
</script>
</head>
<body>
<pre>
<script type="text/vbscript">
   printHello()
</script>
</pre>
</body>
</html>

Of course, the output of the modified VBScript page will be the same text: "Hello World!".

While testing this "src" attribute of the "script" tag, I also notice that the shorthand form of the empty tag does not work:

<script type="text/vbscript" src="VBScript_file_URL"/>

You must use the close tag </script> explicitly!

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 as External Files - Updated in 2015, by Dr. Herong Yang