VBScript Placement : In HTMLPritesh
Placing VBScript Code :
VBScript can be included in HTML file anywhere but we include VBScript ideally only in following four positions –
- Inside <head>…</head> section.
- Inside <body>…</body> section.
- Inside <body>…</body> and <head>…</head> sections.
- Inside external file
Position #1 : Inside Head Section
Generally following position of VBScript placement is preferred when we need to add code for some kind of event such as click event.
<html> <head> <script type="text/Vbscript"> <!-- Function message() Msgbox("Hello VBScript") End Function //--> </script> </head> <body> <input type="button" onclick="message()" value="message" /> </body> </html>
Position #2 : Inside Body Section
Whenever we need to print some message on page load then we prefer body section to place VBScript code. In the below example VBScript is used to generate content.
<html> <head> </head> <body> <script type="text/vbscript"> <!-- document.write("Hello World") //--> </script> </body> </html>
Position #3 : Inside External File
You need to write your all VBScript source code in a simple text file with extension “.vbs” and then include that file as shown above.
Consider below external file called script.vbs –
Function printMessage() Msgbox "Hello World" End Function
Now we need to include the above file in our HTML code then we can write it as –
<html> <head> <script type="text/vbscript" src="script.vbs" ></script> </head> <body> ....... </body> </html>
- We use script tag to include external VBScript file in our HTML file.
- We use script tag if we need to include same VBScript code in multiple HTML files.
- We use script tag so that we can make difference between the VBScript code and HTML code.