0% found this document useful (0 votes)
90 views

The HTML Tag Is Used To Insert A Vbscript Into An HTML Page

VBScript is a lightweight scripting language that can be inserted into HTML documents using <script> tags. VBScript code is interpreted by the browser and can manipulate the HTML document, such as writing text to the page. To ensure browsers that don't support scripting ignore the VBScript code, HTML comments can be added before and after the <script> tags. VBScript code can be placed in the <head> section, such as inside functions called later, or directly in the <body> to immediately write content to the page.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

The HTML Tag Is Used To Insert A Vbscript Into An HTML Page

VBScript is a lightweight scripting language that can be inserted into HTML documents using <script> tags. VBScript code is interpreted by the browser and can manipulate the HTML document, such as writing text to the page. To ensure browsers that don't support scripting ignore the VBScript code, HTML comments can be added before and after the <script> tags. VBScript code can be placed in the <head> section, such as inside functions called later, or directly in the <body> to immediately write content to the page.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

VBScript

What is VBScript?
VBScript is a scripting language
A scripting language is a lightweight programming language
VBScript is a light version of Microsoft's programming language Visual Basic
How Does it Work?
When a VBScript is inserted into an HTML document, the Internet browser will read the HTML and
interpret the VBScript. The VBScript can be executed immediately, or at a later event.

The HTML <script> tag is used to insert a VBScript into an HTML page.
Put a VBScript into an HTML Page
The example below shows how to use VBSript to write text on a web page:

Example (IE Only)Try it yourself


<html>
<body>
<script type="text/vbscript">
document.write("Hello World!")
</script>
</body>
</html>

<html>
<body>
<script type="text/vbscript">
document.write("<h1>Hello World!</h1>")
</script>
</body>
</html>

Example Explained
To insert a VBScript into an HTML page, we use the <script> tag. Inside the <script> tag we use the
type attribute to define the scripting language.
So, the <script type="text/vbscript"> and </script> tells where the VBScript starts and ends:
The document.write command is a standard VBScript command for writing output to a page.
By entering the document.write command between the <script> and </script> tags, the browser will
recognize it as a VBScript command and execute the code line. In this case the browser will write
Hello World! to the page:
<html>
<body>
<script type="text/vbscript">
...
</script>
</body>
</html>

<html>
<body>
<script type="text/vbscript">
document.write("Hello World!")
</script>
</body>
</html>

How to Handle Simple Browsers


Browsers that do not support scripting, will display VBScript as page content.
To prevent them from doing this, the HTML comment tag should be used to "hide" the VBScript.
Just add an HTML comment tag <!-- before the first VBScript statement, and a --> (end of comment)
after the last VBScript statement, like this:
<html>
<body>
<script type="text/vbscript">
<!-document.write("Hello World!")
-->
</script>
</body>
</html>

VBScripts can be placed in the body and in the head section of an HTML document.

Where to Put the VBScript


VBScripts in a page will be executed immediately while the page loads into the browser. This is not
always what we want. Sometimes we want to execute a script when a page loads, or at a later event,
such as when a user clicks a button. When this is the case we put the script inside a function or a sub
procedure, you will learn about procedures in a later chapter.

Scripts in <head>
Put your functions and sub procedures in the head section, this way they are all in one place, and they
do not interfere with page content.

Example (IE Only)


<html>
<head>
<script type="text/vbscript">
function myFunction()
alert("Hello World!")
end function
</script>
</head>
<body onload="myFunction()">
</body>
</html>
Try it yourself

Scripts in <body>
If you don't want your script to be placed inside a function, and especially if your script should write
page content, it should be placed in the body section.

Example (IE Only)


<html>
<head>
</head>
<body>
<script type="text/vbscript">
document.write("This message is written by VBScript")
</script>
</body>
</html>
Try it yourself

You might also like