How to Write HTML Script
With the hypertext markup language (HTML) "script" tags, you can enhance your Web pages with a client-side script like JavaScript or VBScript. Client-side scripting languages let you create features on your website that encourage interactivity with your visitors because they respond to the users' actions. For example, a person may hover over a block of text and have a menu automatically display. With your computer's plain text editor application, you can write your own HTML script to make your pages more dynamic.
Instructions
-
-
1
Launch your text editor and create a new page. Position your cursor underneath the "<body>" tag.
-
2
Type in the beginning and ending "<script></script>" tags. These tags bracket all the content in the file, so <script> is at the beginning and </script> is at the end. Next, assign a "type" to the opening "<script>" element to let the browser know what kind of language you are using. For example, JavaScript is defined as follows:
<script type="text/javascript">
</script> -
-
3
Enter the source of your script between the "<script></script>" tags to embed it directly in the HTML code. For instance, an example of a simple JavaScript source code looks like:
<script type="text/javascript">
document.write("Sample text that you want a browser to display.");
</script>Or type the URL address of an external file inside the beginning script tag. To illustrate:
<script type="text/javascript" src="http://www.yourdomain.com/script.js">
-
4
Type in comment tags before and after your embedded script data to accommodate browsers that do not accept the "<script>" tag. Do this by using the opening "<!--" and closing "//-->" (JavaScript) or " '-->" (VBScript) comment elements.
To illustrate, VBScript looks as follows:
<script type="text/vbscript">
<!--
your script source
'-->
</script>With comment tags, an older browser will no longer display the "<script>" code as content on the Web page.
-
5
Enter "<noscript></noscript>" tags after the last "</script>" element and type in a message between the tags. The message, such as "This browser does not allow JavaScript.," appears in the event that browser does not execute the script.
Your full script code now appears as the following example:
<script type="text/vbscript">
<!--
your script source
'-->
</script>
<noscript>This browser does not allow VBScript.</noscript> -
6
Name your file and save it with the "HTML" ending (extension).
-
1
References
Resources
- Photo Credit laptop 9 image by Harvey Hudson from Fotolia.com