0% found this document useful (0 votes)
81 views

Javasript Codes

The document describes how to add JavaScript code to an HTML page in three ways: 1. By placing <script> tags within the <body> or <<head> tags and writing JavaScript code directly in the page. 2. By placing JavaScript code within HTML comment tags <!-- --> to avoid it being executed. 3. By saving JavaScript code in an external .js file and linking to it using a <script> tag's src attribute, allowing the same code to be used on multiple pages.

Uploaded by

api-3848319
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Javasript Codes

The document describes how to add JavaScript code to an HTML page in three ways: 1. By placing <script> tags within the <body> or <<head> tags and writing JavaScript code directly in the page. 2. By placing JavaScript code within HTML comment tags <!-- --> to avoid it being executed. 3. By saving JavaScript code in an external .js file and linking to it using a <script> tag's src attribute, allowing the same code to be used on multiple pages.

Uploaded by

api-3848319
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

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>

You might also like