JavaScript uses notations, javascript may appear strange to non-programmers. We begin by considering a simple script that dispalys the text "Welcome to JavaScript Programming!" in the body of an XHTML document. All major web browsers contains JavaScript interpreters, which process the commands written in JavaScript.
The JavaScript code we write will appear in the <head> section. The browser interprets the contents of the <head> section first, so the JavaScript programs we write there execute before the <body> of the XHTML document displays.
Displaying a Line of Text
The <script> tag to indicate to the browser that the text which follows is part of a script. The type attribute specifies the type of file as well as the scripting language used in the script-in this case, a text file written in javascript. Both Internet Explorer and Firefox use JavaScript as the default scripting language.
When a browser that does not support scripts encounters the preceding code, it ignores the <script> and </script> tags and the script code in the XHTML comment. Browers that do support scripting will interpret the JavaScript code as expected.(Some browsers require the JavaScript single-line comment // before the ending XHTML comment delimiter(-->) to interpret the script properly.
The JavaScript code we write will appear in the <head> section. The browser interprets the contents of the <head> section first, so the JavaScript programs we write there execute before the <body> of the XHTML document displays.
Displaying a Line of Text
<html>
<head>
<title>A First Program in JavaScript</title>
<script type = "text/javascript">
<!--
document.writeln( "<h1>Welcome to JavaScript Programming!</h1>" );
// -->
</script>
</head>
<body>
</body>
</html>
<head>
<title>A First Program in JavaScript</title>
<script type = "text/javascript">
<!--
document.writeln( "<h1>Welcome to JavaScript Programming!</h1>" );
// -->
</script>
</head>
<body>
</body>
</html>
The <script> tag to indicate to the browser that the text which follows is part of a script. The type attribute specifies the type of file as well as the scripting language used in the script-in this case, a text file written in javascript. Both Internet Explorer and Firefox use JavaScript as the default scripting language.
When a browser that does not support scripts encounters the preceding code, it ignores the <script> and </script> tags and the script code in the XHTML comment. Browers that do support scripting will interpret the JavaScript code as expected.(Some browsers require the JavaScript single-line comment // before the ending XHTML comment delimiter(-->) to interpret the script properly.