Last Modified: 1/29/08
  Computer Training
Execution of JavaScript


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.
Previous Home Next

Course Topics

Client-Side JavaScript

JavaScript as a Programming Language

Execution of JavaScript

'JavaScript Document Object Model

Programming with JavaScript

Using Cookies in JavaScript

JavaScript and DHTML

Homework Assignments

 
Previous Home Next

©1999 UW Technology