What You Should Already Know
Before you continue you should have a basic understanding of the following:
- HTML / XHTML
If you want to study these subjects first, find the tutorials on our Home page.
- A scripting language is a lightweight programming language
Java (developed by Sun Microsystems) is a powerful and much more complex programming language – in the same category as C and C++.
The Real Name is ECMAScript
The language was invented by Brendan Eich at Netscape (with Navigator 2.0), and has appeared in all Netscape and Microsoft browsers since 1996.
The development of ECMA-262 started in 1996, and the first edition of was adopted by the ECMA General Assembly in June 1997.
The standard was approved as an international ISO (ISO/IEC 16262) standard in 1998.
The development of the standard is still in progress.
The example demonstrates how to use JavaSript to write text on a web page.
The code above will produce this output on an HTML page:
Note: If we had not entered the <script> tag, the browser would have treated the document.write(“Hello World!”) command as pure text, and just write the entire line on the page.
HTML Comments to Handle Simple Browsers
Scripts in the head section: Scripts to be executed when they are called, or when an event is triggered, go in the head section. When you place a script in the head section, you will ensure that the script is loaded before anyone uses it.
Scripts in the body section: Scripts to be executed when the page loads go in the body section. When you place a script in the body section it generates the content of the page.
Scripts in both the body and the head section: You can place an unlimited number of scripts in your document, so you can have scripts in both the body and the head section.
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:
Note: Remember to place the script exactly where you normally would write the script!