|
Credit: J. Trauger (JPL/NASA)
There are 5 ways of including JavaScript code in your HTML files:
- You can embed it between <SCRIPT> and </SCRIPT> tags.
See
this
for an example.
This is the usual method.
- A second common method is to include JavaScript code as
an event handler inside HTML elements in Forms. Typically,
the JavaScript code is very small and is usually a call to
a function which may carry out complex tasks. See
this
for the output of a
simple example.
- A third method is to use
<script src=...> tags to read in JavaScript source
from a file. This is an excellent way to modularize and simplify
your code. It also can be used to reduce loading time as particular
JavaScript modules can remain unloaded until/unless a user requests
them.
See this
for an example and this
for the source JavaScript code it calls.
- There exist two other methods that are sometimes used:
(a) using a special
Javascript: URL protocol,
and (b) embedding code with the JavaScript HTML entity, but
we will not discuss them here.
|
|
 |
|
 |