instructional systems
Index:
[Session11] JavaScript 1 (Interactive page)
1 Chapter1
2 Chapter2
3 Chapter3
--3.3 Application of Handling
4 Chapter4
5 Chapter5
Your Location: Home Page  >  [3] Interactive web pages using JavaScript (on condition)  >  [Session11] JavaScript 1 (Interactive page)  >  Chapter3  >  3.1 Preparation in HTML File
Preparation in HTML File
[The purpose of this section]
Learn the procedure of how to use the handling written in JavaScript in HTML file

Three Steps to Use JavaScript File

To use the JavaScript language handling created separately from HTML, you must take the following three steps.

  1. [Preparation in HTML]: Declare to use JavaScript language.  
  2. [Definition of handling]: Group multiple basic handlings into one, and assign a name.
  3. [Application of handling]: Write the name of the handling defined (or predefined) to the position in HTML which you wish to execute.

Now let’s see these three steps by actual examples.

Preparation in HTML File -- Declaration by <head>Element

As is the case where CSS was used, you need to declare to use JavaScript language beforehand by a header element of the HTML file. The following is an example.

<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript" src="./myscript.js"></script>

The first line declares the program used in HTML file is in JavaScript language.
The second line declares that a file named “.myscipt.js”, which is the group of definitions of handlings described in JavaScript language, is to be used in this HTML file. This means that all definitions of handlings for JavaScript are described in the file “./myscript.js”.

Hence, the header element of your HTML file using CSS and JavaScript should look as follows.

............
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <meta http-equiv="Content-Style-Type" content="text/css">
    <link rel="stylesheet" type="text/css" href="../css/mystyle.css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript" src="./myscript.js"></script>
    <title>○○○</title>
   ........
  </head>
............
Copyright (C) Kenichi Sugitani, Hideki Matsuda, Chisato Noguchi and Fumiko Ryu 2005-2006, All Rights Reserved