home page of the browsers publisherunless youve changed the settings) is unavailable. Thats fine.
You
want the browser open, but you dont need to be connected to your ISP. If youre automatically
connected to
the Internet through a local area network in your office or school or cable modem or DSL, thats also
fine.
However, you dont need the network connection for now. Next, follow these steps to enter and
preview
your first JavaScript script:
1. Activate your text editor and create a new, blank document.
2. Type the script in the window exactly as shown in Listing 3-1.
Follow the example slowly and carefully, paying special attention to:
a. The uppercase and lowercase letters
b. The placement of single () and double () quote symbols
c. The usage of parentheses, angle brackets (< and >), and curly braces ({ and })
LISTING 3-1
Source Code for script1.html
<html>
<head>
<title>My First Script</title>
<style type=text/css>
.highlight {color: red}
</style>
<script type=text/javascript>
function showBrowserType() {
document.getElementById(readout).innerHTML =
Your browser says it is: +
<span class=highlight> +
navigator.userAgent + </span>.<hr />;
}
window.onload = showBrowserType;
</script>
</head>
<body>
<h1>Lets Script...</h1>
<hr>
<h1>Lets Script...</h1>
<hr />
<div id=readout></div>
</body>
</html>
3. Save the document with the name script1.html.
4. Switch to your browser.
5. Choose Open (or Open File on some browsers) from the File menu, and select script1.html.
(On some browsers, you have to click a Browse button to reach the File dialog box.)
22
Part I
Getting Started with JavaScript