Javascript - Code implementation

October 2017

Where to insert the JavaScript in your HTML page?

Ther are several ways to insert JavaScript in an HTML page:

Using the <SCRIPT> tag

The JavaScript code can be inserted wherever you want in your web page, however, you must ensure that the browser has fully loaded before your script before executing an instruction. Indeed, when the browser loads your web page, it processes from the top to the bottom. In most cases, we try to put the maximum number of elements of the script in the header (between the <HEAD> and </HEAD>). Javascript events will in turn be placed in the body of the page (between the <BODY> and </BODY> tags) as an attribute of an HTML control ...
<SCRIPT language="Javascript">


Put your code here

// -->


The argument of the <SCRIPT> tag describes the language used. It can be "JavaScript" "JavaScript1.1" "JavaScript1.2".
It can also be used for other programming languages (e.g VBScript).
To use different versions of JavaScript, while retaining a certain level of compatibility, simply declare multiple SCRIPT tags having each as parameter a corresponding version of JavaScript.

In an external file

It is possible to put JavaScript code attached to a file. The code to insert is as follows:
<SCRIPT LANGUAGE="Javascript" SRC="url/file.js"> </SCRIPT>

Where url/file.js corresponds to the path to the file containing the JavaScript code.

Using events

An event is a user action, such as mouse click:
<balise eventHandler="Javascript to be inserted">

Where eventHandler is the name of the event.

Orignal document published on


Published by jak58. Latest update on May 20, 2013 at 11:38 AM by jak58.
This document, titled "Javascript - Code implementation," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (