How to Put a JavaScript Into an HTML Page
<html>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>
output on an HTML page: Hello World!
The word document.write is a standard JavaScript command for writing output to a
page.
Just add an HTML comment tag <!-- before the first JavaScript statement, and a --> (end
of comment) after the last JavaScript statement.
Scripts in both the body and the head section:
<html>
<head>
<script type="text/javascript">
....
</script>
</head>
<body>
<script type="text/javascript">
....
</script>
</body>
Using an External JavaScript
Sometimes you might want to run the same JavaScript on several pages, without having to write
the same script on every page.
To simplify this, you can write a JavaScript in an external file. Save the external JavaScript file with
a .js file extension.
Note: The external script cannot contain the <script> tag!
To use the external script, point to the .js file in the "src" attribute of the <script> tag:
<html>
<head>
<script src="xxx.js"></script>
</head>
<body>
</body>
</html>