Source Code For Script1.html: Listing 3-1
Source Code For Script1.html: Listing 3-1
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
<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.
22
Part I