Using VBScript, you can write code directly inside HTML files, and this code will be executed when such a file is loaded in a browser — i.e., on the client side. This code must be placed inside the paired <script> tag, whose language attribute specifies the scripting language.
As an example, The code shows that displays a greeting window when you click on the text “Hello, World!”.
<html> <head> <script language="VBScript"> Sub hello() Msgbox "Hello, World, again!" End Sub </script> </head> <body> <h1 onclick="hello">Hello, World!</h1> </body> </html>
To create and run this example, do the following:
- Open the standard Windows application Notepad.
- In the window that opens, type the suggested code.
- Save the code in a file with the .html extension, for example, Hello-world.html in the root directory of drive D:.
- Open the file you created, either by double-clicking it with the left mouse button or pressing Enter.
- In the browser window, the greeting you wrote (“Hello, World!”) will be displayed. If your browser blocks the execution of scripts or ActiveX elements, click the message that appears in the browser window and allow the blocked content to run.
- Click the “Hello, World!” text in the browser window and verify that the script executes.