Add Scripts to Your Web Pages
The
way you add scripts to your Web pages is much alike you put any contents on HTML pages.
Scripts are enclosed between the container tags: <SCRIPT> </SCRIPT>. In this
article, we show you how to add JavaScripts and VBScripts to your HTML files.
1. Methods to add scripts to your Web pages:
- Embedded scripts: These scripts will be placed on your HTML
files. That means you can include any JavaScripts or VBScripts directly on your HTML
file.
- Linked scripts: These scripts are stored on a Web server and
linked to the HTML files. That means you write the scripts and save them in separate files
and then link the scripts to the HTML by calling script file names.
- If you want to use linked scripts, you have to write it,
save it in the format: filename.extension(filename dot extension) in which the file
extension must be either "JS" for JavaScripts and "VBS" for Microsoft
VBScripts. Also note that the extension is not case sensitive, which means you could use
"js" or "JS".
- You may put your scripts anywhere in the HTML file.
Normally, the declaration of the script is placed within the <HEAD></HEAD>
tags or within the <BODY></BODY> tags..
2. Script tag and attributes: <SCRIPT></SCRIPT>
- In HTML 4.0, the TYPE
attribute specifes what types of scripts, a JavaScript or a VBScript, you are going to
embed in HTML file. Example: <SCRIPT TYPE="text/javascript">
- Prior to HTML 4.0, you have to use the LANGUAGE
attribute instead of TYPE attribute to specify if the script is a JavaScript or a
VBScript. Example: <SCRIPT LANGUAGE="javascript">
- The SRC attribute points to the location of the
scripts on the Web server if you use linked scripts. However, if you embed the scripts on
your HTML files, you can obmit this attribute.
3. Add JavaScripts to your HTML files
Example1: Add an
embedded JavaScript
<HTML>
<HEAD><TITLE>An example of embedding A JavaScript</TITLE>
<SCRIPT TYPE="text/javascript">
<!-- Hiding scripts from old browser
Your Script code goes here!
//End hiding from browser -->
</SCRIPT>
</HEAD>
<BODY>
<p>Other HTML code goes here!:</p>
</BODY>
</HTML>