VBScript Tutorials - Herong's Tutorial Examples - v6.01, by Dr. Herong Yang
Including VBScript Code as External Files
This section provides a quick description of how to save VBScript code 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) 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