Learn Different Ways to Integrate JavaScript into Your HTML Pages.
As you know, there are two places you can put your JavaScripts in an HTML page: in either the head or body section. In addition, I have told you that you can either embed JavaScript directly into the HTML page or reference it in as an external .js file. One more way you can integrate JavaScript into an HTML page is as a component in an HTML tag.
Placing JavaScripts in the Body Section of the HTML page
JavaScripts embedded with the <SCRIPT> and </SCRIPT> tags can be placed anywhere in the body section of an HTML page. Scripts embedded in the body section are executed as part of the HTML document when the page loads. This enables the script to begin executing automatically as the page loads. For example, the statements shown below demonstrate how to embed a JavaScript within the body section of an HTML page.
<BODY>
<SCRIPT LANGUAGE=”JavaScript” TYPE=”Text/JavaScript”>
document.write(“This JavaScript is located in the body
section”);
</SCRIPT>
</BODY>
Similarly, you can embed multiple JavaScripts in HTML pages:
<BODY>
<SCRIPT LANGUAGE=”JavaScript” TYPE=”Text/JavaScript”>
document.write(“This first JavaScript is located in the
body section”);
</SCRIPT>
<BR>
<SCRIPT LANGUAGE=”JavaScript” TYPE=”Text/JavaScript”>
document.write(“This second JavaScript is also located in
the body section”);
</SCRIPT>
</BODY>